using System; using System.Collections.Generic; using System.Linq; using System.Text; using Payroll.BO; using Ease.CoreV35.DataAccess; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using Ease.Core.Utility; namespace Payroll.Service { #region ClaimPaymentService Service public class ClaimPaymentService : ServiceTemplate, IClaimPaymentService { public ClaimPaymentService() { } private void MapObject(ClaimPayment oClaimPayment, DataReader oReader) { base.SetObjectID(oClaimPayment,oReader.GetInt32("ClaimPaymentID").Value); oClaimPayment.IsAnnualDisbursment = oReader.GetBoolean("IsAnnualDisbursment", false); oClaimPayment.IsActualPayment = oReader.GetBoolean("IsActualPayment", false); oClaimPayment.IsNotMaximum = oReader.GetBoolean("IsNotMaximum", false); oClaimPayment.ClaimType = (EnumClaimType)oReader.GetInt32("ClaimType").Value; oClaimPayment.MaxServiceLength = oReader.GetDouble("MaxServiceLength") == null ? 0.0 : oReader.GetDouble("MaxServiceLength").Value; oClaimPayment.MonthDifference = oReader.GetInt32("MonthDifference").Value; oClaimPayment.NoOfDependent = oReader.GetInt32("NoOfDependent").Value; oClaimPayment.Status = (EnumStatus)oReader.GetInt32("Status").Value; oClaimPayment.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value; oClaimPayment.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oClaimPayment.ModifiedBy = oReader.GetString("ModifiedBy") == null ? null : oReader.GetInt32("ModifiedBy").Value; oClaimPayment.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oClaimPayment.PayrollTypeID = oReader.GetString("PayrollTypeID") == null ? null : oReader.GetInt32("PayrollTypeID").Value; this.SetObjectState(oClaimPayment, Ease.Core.ObjectState.Saved); } private void MapChildObject(ClaimPaymentGrades oClaimPaymentGrade, DataReader oReader) { base.SetObjectID(oClaimPaymentGrade, oReader.GetInt32("ClaimPaymentGradesID").Value); oClaimPaymentGrade.ClaimPaymentID = oReader.GetInt32("ClaimPaymentID") == null ? 0 : oReader.GetInt32("ClaimPaymentID").Value; oClaimPaymentGrade.GradeID = oReader.GetInt32("GradeID") == null ? 0 : oReader.GetInt32("GradeID").Value; oClaimPaymentGrade.Amount = oReader.GetDouble("Amount") == null ? 0.0 : oReader.GetDouble("Amount").Value; this.SetObjectState(oClaimPaymentGrade, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ClaimPayment oClaimPayment = new ClaimPayment(); MapObject(oClaimPayment, oReader); return oClaimPayment as T; } protected ClaimPayment CreateObject(DataReader oReader) { ClaimPayment oClaimPayment = new ClaimPayment(); MapObject(oClaimPayment, oReader); return oClaimPayment; } private List CreateChilds(DataReader oReader) { List oClaimPaymentGrades = new List(); ClaimPaymentGrades oClaimPaymentGrade; while (oReader.Read()) { oClaimPaymentGrade = new ClaimPaymentGrades(); oClaimPaymentGrade = CreateChild(oReader); oClaimPaymentGrades.Add(oClaimPaymentGrade); } return oClaimPaymentGrades; } private ClaimPaymentGrades CreateChild(DataReader oReader) { ClaimPaymentGrades oClaimPaymentGrades = new ClaimPaymentGrades(); MapChildObject(oClaimPaymentGrades, oReader); return oClaimPaymentGrades; } #region Service implementation public ClaimPayment Get(int id) { ClaimPayment oClaimPayment = new ClaimPayment(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ClaimPaymentDA.Get(tc, id)); if (oreader.Read()) { oClaimPayment = 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 oClaimPayment; } public List Get(EnumStatus status, int payrollTypeID) { #region Cache Header List attnNationalHolidays =null; //if (attnNationalHolidays != null) // return attnNationalHolidays; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimPaymentDA.Get(tc, status, payrollTypeID)); attnNationalHolidays = 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 attnNationalHolidays; } public List GetClaimPaymentGrades(int attnNationalHolidayID) { List oClaimPaymentGrades = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimPaymentDA.GetChild(tc, attnNationalHolidayID)); oClaimPaymentGrades = this.CreateChilds(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 oClaimPaymentGrades; } public void Save(List oClaimPayments) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int ClaimPaymentID = tc.GenerateID("ClaimPayment", "ClaimPaymentID"); int ClaimPaymentGradesID = tc.GenerateID("ClaimPaymentGrades", "ClaimPaymentGradesID"); foreach (ClaimPayment oClaimPayment in oClaimPayments) { if (oClaimPayment.IsNew) { base.SetObjectID(oClaimPayment, ClaimPaymentID); ClaimPaymentDA.Insert(tc, oClaimPayment); ClaimPaymentID++; } else { ClaimPaymentDA.Update(tc, oClaimPayment); ClaimPaymentDA.DeleteChild(tc, oClaimPayment.ID); } foreach (ClaimPaymentGrades item in oClaimPayment.ClaimPaymentGrades) { base.SetObjectID(item, ClaimPaymentGradesID); item.ClaimPaymentID = oClaimPayment.ID; ClaimPaymentDA.InsertChild(tc, item); ClaimPaymentGradesID++; } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int Save(ClaimPayment oClaimPayment) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oClaimPayment.IsNew) { int id = tc.GenerateID("ClaimPayment", "ClaimPaymentID"); base.SetObjectID(oClaimPayment, id); ClaimPaymentDA.Insert(tc, oClaimPayment); } else { ClaimPaymentDA.Update(tc, oClaimPayment); ClaimPaymentDA.DeleteChild(tc, oClaimPayment.ID); } foreach (ClaimPaymentGrades item in oClaimPayment.ClaimPaymentGrades) { int id = tc.GenerateID("ClaimPaymentGrades", "ClaimPaymentGradesID"); base.SetObjectID(item, id); item.ClaimPaymentID = oClaimPayment.ID; ClaimPaymentDA.InsertChild(tc, item); } tc.End(); return oClaimPayment.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void DeleteByType(EnumClaimType claimType) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimPaymentDA.DeleteChildByType(tc, claimType); ClaimPaymentDA.DeleteByType(tc, claimType); 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(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimPaymentDA.DeleteChild(tc, id); ClaimPaymentDA.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 } } #endregion } #endregion }