using System; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using System.Collections.Generic; using Ease.Core.Utility; namespace HRM.DA { public class DivisionService : ServiceTemplate, IDivisionService { #region constructor public DivisionService() { } #endregion #region Object private void MapObject(Division oDivision, DataReader oReader) { base.SetObjectID(oDivision, oReader.GetInt32("DIVISIONID").Value); oDivision.Code = oReader.GetString("CODE"); oDivision.Name = oReader.GetString("NAME"); oDivision.Sequence = oReader.GetInt32("SequenceNo").Value; oDivision.Status = (EnumStatus)oReader.GetInt32("Status").Value; oDivision.CreatedBy = oReader.GetInt32("CreatedBy", 0); oDivision.CreatedDate = oReader.GetDateTime("CreationDate").Value; oDivision.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oDivision.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oDivision, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Division oDivision = new Division(); MapObject(oDivision, oReader); return oDivision as T; } #endregion #region Service implementation public Division Get(int id) { Division oDivision = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(DivisionDA.Get(tc, id)); if (oreader.Read()) { oDivision = 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 oDivision; } public Division Get(string sCode) { Division oDivision = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(DivisionDA.Get(tc, sCode)); if (oreader.Read()) { oDivision = 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 oDivision; } public List Get() { List countries = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(DivisionDA.Get(tc)); countries = 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 countries; } public List Get(EnumStatus status) { List countries = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(DivisionDA.Get(tc, status)); countries = 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 countries; } public List Get(EnumStatus status, int payrollTypeId) { List countries = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(DivisionDA.Get(tc, status)); countries = 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 countries; } public int Save(Division oDivision) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oDivision.IsNew) { int id = tc.GenerateID("DIVISION", "DIVISIONID"); base.SetObjectID(oDivision, id); DivisionDA.Insert(tc, oDivision); } else { DivisionDA.Update(tc, oDivision); } tc.End(); return oDivision.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); DivisionDA.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 } }