using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using System; using System.Collections.Generic; using HRM.BO; namespace HRM.DA { public class ApproveFinantialDataService : ServiceTemplate, IApproveFinantialDataService { public ApproveFinantialDataService() { } private void MapObject(ApproveFinantialData oApproveFinantialData, DataReader oReader) { base.SetObjectID(oApproveFinantialData, oReader.GetInt32("ApproveID").Value); oApproveFinantialData.FinantialDataType = (EnumApprovalFinancialData)oReader.GetInt32("FinanatialDataType"); oApproveFinantialData.EmployeeID = oReader.GetInt32("EmployeeID", 0); oApproveFinantialData.ObjectID = oReader.GetInt32("ObjectID").GetValueOrDefault(); oApproveFinantialData.SalaryMonth = oReader.GetDateTime("SalaryMonth").GetValueOrDefault(); oApproveFinantialData.Approvedby = oReader.GetInt32("Approvedby").GetValueOrDefault(); oApproveFinantialData.ApprovedDate = oReader.GetDateTime("ApprovedDate").GetValueOrDefault(); this.SetObjectState(oApproveFinantialData, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ApproveFinantialData oApproveFinantialData = new ApproveFinantialData(); MapObject(oApproveFinantialData, oReader); return oApproveFinantialData as T; } #region Service implementation public ApproveFinantialData Get(int EmpID, DateTime dt) { ApproveFinantialData oApproveFinantialData = new ApproveFinantialData(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ApproveFinantialDataDA.Get(tc, EmpID, dt)); if (oreader.Read()) { oApproveFinantialData = this.CreateObject(oreader); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oApproveFinantialData; } public List Get(int id) { List ApproveFinantialDatas = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ApproveFinantialDataDA.Get(tc, id)); ApproveFinantialDatas = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return ApproveFinantialDatas; } public List GetByMonth(DateTime dtStart, DateTime dtEnd) { List ApproveFinantialDatas = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ApproveFinantialDataDA.GetByMonth(tc, dtStart, dtEnd)); ApproveFinantialDatas = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return ApproveFinantialDatas; } public List Get() { List ApproveFinantialDatas = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ApproveFinantialDataDA.Get(tc)); ApproveFinantialDatas = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return ApproveFinantialDatas; } public void Save(List items) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (ApproveFinantialData item in items) { int id = tc.GenerateID("ApproveFinantialData", "ApproveID"); base.SetObjectID(item, id); ApproveFinantialDataDA.Insert(tc, item); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Delete(ApproveFinantialData item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ApproveFinantialDataDA.Delete(tc, item); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Delete(List items) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (var item in items) { ApproveFinantialDataDA.Delete(tc, item); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion public List GetByType(int selectedType) { List ApproveFinantialDatas = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ApproveFinantialDataDA.GetByType(tc, selectedType)); ApproveFinantialDatas = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return ApproveFinantialDatas; } } }