using System; using System.Data; using System.Linq; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Payroll.BO; using Ease.CoreV35.Caching; namespace Payroll.Service { public class PremiumProcessDetailService : ServiceTemplate, IPremiumProcessDetailService { private void MapObject(PremiumProcessDetail oPremiumProcess, DataReader oReader) { this.SetObjectID(oPremiumProcess, oReader.GetID("PremiumProcessDetailID")); oPremiumProcess.EmployeeID = oReader.GetID("EmployeeID"); oPremiumProcess.PremiumProcessID = oReader.GetID("PremiumProcessID"); oPremiumProcess.Gross = oReader.GetDouble("Gross").HasValue ? oReader.GetDouble("Gross").Value : 0; oPremiumProcess.Basic = oReader.GetDouble("Basic").HasValue ? oReader.GetDouble("Basic").Value : 0; oPremiumProcess.AssuredAmount = oReader.GetDouble("AssuredAmount").HasValue ? oReader.GetDouble("AssuredAmount").Value : 0; oPremiumProcess.PremiumAmount = oReader.GetDouble("PremiumAmount").HasValue ? oReader.GetDouble("PremiumAmount").Value : 0; this.SetObjectState(oPremiumProcess, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { PremiumProcessDetail oPremiumProcess = new PremiumProcessDetail(); MapObject(oPremiumProcess, oReader); return oPremiumProcess as T; } protected PremiumProcessDetail CreateObject(DataReader oReader) { PremiumProcessDetail oPremiumProcess = new PremiumProcessDetail(); MapObject(oPremiumProcess, oReader); return oPremiumProcess; } public PremiumProcessDetail Get(ID id) { PremiumProcessDetail oPremiumProcess = new PremiumProcessDetail(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oReader = new DataReader(PremiumProcessDetailDA.Get(tc, id)); if (oReader.Read()) { oPremiumProcess = 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 oPremiumProcess; } public ObjectsTemplate Get() { ObjectsTemplate oPremiumProcesses = new ObjectsTemplate(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PremiumProcessDetailDA.Get(tc)); oPremiumProcesses = this.CreateObjects(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 oPremiumProcesses; } public ID Save(PremiumProcessDetail oPremiumProcess) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oPremiumProcess.IsNew) { int id = tc.GenerateID("PremiumProcessDetail", "PremiumProcessDetailID"); base.SetObjectID(oPremiumProcess, ID.FromInteger(id)); PremiumProcessDetailDA.Insert(tc, oPremiumProcess); } else { PremiumProcessDetailDA.Update(tc, oPremiumProcess); } tc.End(); return oPremiumProcess.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); PremiumProcessDetailDA.Delete(tc, id); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public ObjectsTemplate GetDetails(ID id) { ObjectsTemplate oPremiumProcesses = new ObjectsTemplate(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PremiumProcessDetailDA.GetDetails(tc,id)); oPremiumProcesses = this.CreateObjects(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 oPremiumProcesses; } } }