using HRM.BO; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using System; using System.Collections.Generic; namespace HRM.DA { #region Term Service public class TermService : ServiceTemplate, ITermService { #region Private functions and declaration #endregion public TermService() { } private void MapObject(Term oTerm, DataReader oReader) { base.SetObjectID(oTerm, oReader.GetInt32("termID").Value); oTerm.Code = oReader.GetString("code"); oTerm.Name = oReader.GetString("name"); oTerm.NameInBangla = oReader.GetString("nameinbangla", true, null); oTerm.TermType = (EnumTermType)oReader.GetInt32("TermType").Value; oTerm.Sequence = oReader.GetInt32("SequenceNo").Value; oTerm.Status = (EnumStatus)oReader.GetInt32("Status").Value; oTerm.payrolltypeid = oReader.GetInt32("payrolltypeid").Value; oTerm.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value; oTerm.CreatedDate = oReader.GetDateTime("CreationDate").Value; oTerm.ModifiedBy = oReader.GetString("ModifiedBy") == null ? 0 : oReader.GetInt32("ModifiedBy").Value; oTerm.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oTerm, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Term oTerm = new Term(); MapObject(oTerm, oReader); return oTerm as T; } protected Term CreateObject(DataReader oReader) { Term oTerm = new Term(); MapObject(oTerm, oReader); return oTerm; } #region Service implementation public Term Get(int id) { Term oTerm = new Term(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TermDA.Get(tc, id)); if (oreader.Read()) { oTerm = 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 oTerm; } public List Get(EnumStatus status, int payrolltypeid) { List terms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(TermDA.Get(tc, status, payrolltypeid)); terms = 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 terms; } public List GetBySlabTerm(EnumTermType slabType, int payrolltypeid) { List terms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(TermDA.GetBySlabTerm(tc, slabType, payrolltypeid)); terms = 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 terms; } public int Save(Term oTerm) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oTerm.IsNew) { int id = tc.GenerateID("Term", "TermID"); base.SetObjectID(oTerm, id); int seqNo = tc.GenerateID("Term", "SequenceNO"); oTerm.Sequence = seqNo; TermDA.Insert(tc, oTerm); } else { TermDA.Update(tc, oTerm); } tc.End(); return oTerm.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); TermDA.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 List GetAllTerm(int payrollTypeID, EnumStatus status, string code, string name) { List terms = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(TermDA.GetAllTerm(tc, payrollTypeID, status, code, name)); terms = 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 terms; } #endregion } #endregion }