using System; using Ease.Core.Model; using Ease.Core.DataAccess; using System.Collections.Generic; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { public class MedicalBenifitSetupService : ServiceTemplate { #region Private functions and declaration public MedicalBenifitSetupService() { } private void MapObject(MedicalBenifitSetup medicalBenifitSetup, DataReader oReader) { base.SetObjectID(medicalBenifitSetup, oReader.GetInt32("SetupID").Value); medicalBenifitSetup.GradeID = oReader.GetInt32("GradeID").Value; medicalBenifitSetup.MemberAmount = oReader.GetDouble("MemberAmount").Value; medicalBenifitSetup.AllowedPerson = oReader.GetInt32("AllowedPerson").Value; //medicalBenifitSetup.LastProcessDate = oReader.GetDateTime("LastProcessDate") == null ? DateTime.MinValue : oReader.GetDateTime("LastProcessDate").Value; this.SetObjectState(medicalBenifitSetup, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { MedicalBenifitSetup medicalBenifitSetup = new MedicalBenifitSetup(); MapObject(medicalBenifitSetup, oReader); return medicalBenifitSetup as T; } #endregion #region Service implementation public List Get() { List medicalBenifitSetups = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(MedicalBenifitSetupDA.Get(tc)); medicalBenifitSetups = 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 medicalBenifitSetups; } public MedicalBenifitSetup Get(int gradeId) { MedicalBenifitSetup medicalBenifitSetup = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(MedicalBenifitSetupDA.Get(tc, gradeId)); if (dr.Read()) { medicalBenifitSetup = this.CreateObject(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 medicalBenifitSetup; } public void Save(List medicalBenifitSetups) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("MedicalBenifitSetup", "SetupID"); foreach (MedicalBenifitSetup mbSetUp in medicalBenifitSetups) { base.SetObjectID(mbSetUp, (id)); if (MedicalBenifitSetupDA.IsExist(tc, mbSetUp.GradeID)) { MedicalBenifitSetupDA.Update(tc, mbSetUp); } else { MedicalBenifitSetupDA.Insert(tc, mbSetUp); } 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 } }