using System; using System.Data; using System.Linq; using Ease.CoreV35; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Payroll.BO; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using Ease.Core.Utility; namespace Payroll.Service { public class ClaimRuleService : ServiceTemplate, IClaimRuleService { public ClaimRuleService() { } private void MapObject(ClaimRule oClaimRule, DataReader oReader) { base.SetObjectID(oClaimRule, oReader.GetInt32("ClaimRuleID").Value); oClaimRule.IsAnnualBalance = (bool)oReader.GetBoolean("IsAnnualBalance").Value; oClaimRule.OnceMonthly = oReader.GetBoolean("OnceMonthly"); oClaimRule.OnceDaily = oReader.GetBoolean("OnceDaily"); oClaimRule.IsAtActualPayment = (bool)oReader.GetBoolean("IsAtActualPayment").Value; oClaimRule.NotMaximum = (float)oReader.GetFloat("NotMaximum").Value; oClaimRule.MaxServiceLength = (int)oReader.GetInt32("MaxServiceLength").Value; oClaimRule.MonthDurationFromLastClaim = (int)oReader.GetInt32("MonthDurationFromLastClaim").Value; oClaimRule.NoOfDependent = (int)oReader.GetInt32("NoOfDependent").Value; oClaimRule.WFStatus = (enumwfStatus)oReader.GetInt32("WFStatus"); oClaimRule.ClaimBasicID = oReader.GetString("ClaimBasicID") == null ? 0 : oReader.GetInt32("ClaimBasicID").Value; oClaimRule.FixedAmount = (float)oReader.GetFloat("FixedAmount").Value; oClaimRule.IsDesignationWiseDifferent = (bool)oReader.GetBoolean("IsGradeWiseDifferent").Value; oClaimRule.AllowAdvance = (bool)oReader.GetBoolean("AllowAdvance").Value; oClaimRule.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value; oClaimRule.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oClaimRule.ModifiedBy = oReader.GetString("ModifiedBy") == null ? null : oReader.GetInt32("ModifiedBy").Value; oClaimRule.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oClaimRule.ClaimBasicName = oReader.GetString("ClaimBasicName", true, null); this.SetObjectState(oClaimRule, Ease.Core.ObjectState.Saved); } private void MapObjectClaimRuleGrades(ClaimRuleDesignations oClaimRuleGrades, DataReader oReader) { base.SetObjectID(oClaimRuleGrades, oReader.GetInt32("ClaimRuleGradesID").Value); oClaimRuleGrades.ClaimPaymentGradesID = oReader.GetString("ClaimPaymentGradesID") == null ? 0 : oReader.GetInt32("ClaimPaymentGradesID").Value; oClaimRuleGrades.ClaimRuleID = oReader.GetString("ClaimRuleID") == null ? 0 : oReader.GetInt32("ClaimRuleID").Value; oClaimRuleGrades.ClaimBasicItemId = oReader.GetString("ClaimBasicItemId") == null ? 0 : oReader.GetInt32("ClaimBasicItemId").Value; oClaimRuleGrades.DesignationID = oReader.GetString("GradeID") == null ? 0 : oReader.GetInt32("GradeID").Value; oClaimRuleGrades.Amount = (float)oReader.GetFloat("Amount").Value; this.SetObjectState(oClaimRuleGrades, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ClaimRule oClaimRule = new ClaimRule(); MapObject(oClaimRule, oReader); return oClaimRule as T; } protected ClaimRuleDesignations CreateObject(DataReader oReader) { ClaimRuleDesignations oClaimRuleGrades = new ClaimRuleDesignations(); MapObjectClaimRuleGrades(oClaimRuleGrades, oReader); return oClaimRuleGrades; } protected List CreateClaimRuleGradeObjects(DataReader oReader) { List claimRuleGrades = new List(); while (oReader.Read()) { ClaimRuleDesignations item = CreateObject(oReader); claimRuleGrades.Add(item); } return claimRuleGrades; } #region Service implementation public ClaimRule Get(int id) { ClaimRule oClaimRule = new ClaimRule(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ClaimRuleDA.Get(tc, id)); if (oreader.Read()) { oClaimRule = 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 oClaimRule; } public ClaimRule Get(int claimID, int DesignationID) { ClaimRule oClaimRule = new ClaimRule(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ClaimRuleDA.Get(tc, claimID, DesignationID)); if (oreader.Read()) { oClaimRule = 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 oClaimRule; } public List Get() { #region Cache Header List claimRules = new List(); //if (claimRules != null) // return claimRules; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRuleDA.Get(tc)); claimRules = 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 claimRules; } public List GetByClaimBasicID(int claimBasicID) { #region Cache Header List claimRules = new List(); #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRuleDA.GetByClaimBasicID(tc, claimBasicID)); claimRules = 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 claimRules; } public void Save(List oClaimRules) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("ClaimRule", "ClaimRuleID"); foreach (ClaimRule oClaimRule in oClaimRules) { if (oClaimRule.IsNew) { base.SetObjectID(oClaimRule, id); ClaimRuleDA.Insert(tc, oClaimRule); id++; } else { ClaimRuleDA.Update(tc, oClaimRule); } } 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(ClaimRule oClaimRule) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oClaimRule.IsNew) { int id = tc.GenerateID("ClaimRule", "ClaimRuleID"); base.SetObjectID(oClaimRule, id); ClaimRuleDA.Insert(tc, oClaimRule); } else { ClaimRuleDA.Update(tc, oClaimRule); } ClaimRule cr = new ClaimRule(); DeleteClaimRuleGradesByClaimRuleID(oClaimRule.ID); if (oClaimRule.ClaimRuleDesignations != null && oClaimRule.ClaimRuleDesignations.Count > 0) { foreach (ClaimRuleDesignations item in oClaimRule.ClaimRuleDesignations) { item.ClaimRuleID = oClaimRule.ID; } SaveClaimRuleGrades(oClaimRule.ClaimRuleDesignations); } tc.End(); return oClaimRule.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(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimRuleDA.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 void DeleteByClaimBasicID(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimRuleDA.DeleteByClaimBasicID(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 #region Service implementation child public ClaimRuleDesignations GetClaimRuleGrades(int id) { ClaimRuleDesignations oClaimRuleGrades = new ClaimRuleDesignations(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ClaimRuleDA.GetClaimRuleGrades(tc, id)); if (oreader.Read()) { oClaimRuleGrades = 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 oClaimRuleGrades; } public List GetClaimRuleGrades() { List claimRuleGrades = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRuleDA.GetClaimRuleGrades(tc)); claimRuleGrades = this.CreateClaimRuleGradeObjects(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 claimRuleGrades; } public List GetClaimRuleGradesByClaimRuleID(int claimRuleID) { #region Cache Header List claimRuleGrades = new List(); //if (claimRuleGrades != null) // return claimRuleGrades; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ClaimRuleDA.GetClaimRuleGradesByClaimRuleID(tc, claimRuleID)); claimRuleGrades = this.CreateClaimRuleGradeObjects(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 claimRuleGrades; } public void SaveClaimRuleGrades(List oClaimRuleGrades) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("ClaimRuleGrades", "ClaimRuleGradesID"); foreach (ClaimRuleDesignations oClaimRuleGrade in oClaimRuleGrades) { if (oClaimRuleGrade.IsNew) { base.SetObjectID(oClaimRuleGrade, id); ClaimRuleDA.InsertClaimRuleGrades(tc, oClaimRuleGrade); id++; } else { ClaimRuleDA.UpdateClaimRuleGrades(tc, oClaimRuleGrade); } } 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 SaveClaimRuleGrades(ClaimRuleDesignations oClaimRuleGrade) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oClaimRuleGrade.IsNew) { int id = tc.GenerateID("ClaimRuleGrades", "ClaimRuleGradesID"); base.SetObjectID(oClaimRuleGrade, id); ClaimRuleDA.InsertClaimRuleGrades(tc, oClaimRuleGrade); } else { ClaimRuleDA.UpdateClaimRuleGrades(tc, oClaimRuleGrade); } tc.End(); return oClaimRuleGrade.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void DeleteClaimRuleGrades(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimRuleDA.DeleteClaimRuleGrades(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 void DeleteClaimRuleGradesByClaimRuleID(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ClaimRuleDA.DeleteClaimRuleGradesByClaimRuleID(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 } }