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 OpiItem Service public class OpiItemService : ServiceTemplate, IOpiItemService { #region Private functions and declaration public OpiItemService() { } private void MapObject(OpiItem oOpiItem, DataReader oReader) { base.SetObjectID(oOpiItem, oReader.GetInt32("OpiItemID").Value); oOpiItem.Code = oReader.GetString("Code"); oOpiItem.Name = oReader.GetString("Name"); oOpiItem.OpiType = (EnumOpiType)oReader.GetInt32("OpiType").Value; oOpiItem.Sequence = oReader.GetInt32("SequenceNO").HasValue ? oReader.GetInt32("SequenceNo").Value : 0; oOpiItem.Status = (EnumStatus)oReader.GetInt32("Status").Value; oOpiItem.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value; oOpiItem.CreatedDate = oReader.GetDateTime("CreationDate").Value; oOpiItem.ModifiedBy = oReader.GetString("ModifiedBy") == null ? 0 : oReader.GetInt32("ModifiedBy").Value; ; oOpiItem.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oOpiItem, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { OpiItem oOpiItem = new OpiItem(); MapObject(oOpiItem, oReader); return oOpiItem as T; } protected OpiItem CreateObject(DataReader oReader) { OpiItem oOpiItem = new OpiItem(); MapObject(oOpiItem, oReader); return oOpiItem; } #endregion #region Service implementation public OpiItem Get(int id) { OpiItem oOpiItem = new OpiItem(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oReader = new DataReader(OpiItemDA.Get(tc, id)); if (oReader.Read()) { oOpiItem = 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 oOpiItem; } public List Get() { List oOpiItems = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(OpiItemDA.Get(tc)); oOpiItems = this.CreateObjects(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 oOpiItems; } public List Get(EnumStatus status) { List opiitems = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OpiItemDA.Get(tc, status)); opiitems = 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 opiitems; } public List Get(EnumStatus status, int payrollTypeID) { List Banks = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OpiItemDA.Get(tc, status, payrollTypeID)); Banks = 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 Banks; } public List Get(string opiID) { throw new NotImplementedException(); } public List Get(EnumOpiType opiType, EnumStatus status) { List opiitems = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OpiItemDA.Get(tc, opiType, status)); opiitems = 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 opiitems; } public int Save(OpiItem oOpiItem) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oOpiItem.IsNew) { int id = tc.GenerateID("OpiItem", "OpiItemID"); base.SetObjectID(oOpiItem, id); int seqNo = tc.GenerateID("OpiItem", "SequenceNo"); oOpiItem.Sequence = seqNo; OpiItemDA.Insert(tc, oOpiItem); } else { OpiItemDA.Update(tc, oOpiItem); } tc.End(); return oOpiItem.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); OpiItemDA.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 GetMonthyIndividualAndOneOff(int payrolltypeid, EnumStatus status) { List op = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OpiItemDA.GetMonthyIndividualAndOneOff(tc, payrolltypeid, status)); op = 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 op; } #endregion #region IOpiItemService Members #endregion } #endregion }