using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { #region OutsideDuty Service [Serializable] public class OutsideDutyService : ServiceTemplate, IOutsideDutyService { public OutsideDutyService() { } private void MapObject(OutsideDuty oOutsideDuty, DataReader oReader) { base.SetObjectID(oOutsideDuty, oReader.GetInt32("OutsideDutyID").Value); oOutsideDuty.Name = oReader.GetString("Name", string.Empty); oOutsideDuty.Sequence = oReader.GetInt32("SequenceNo", 0); oOutsideDuty.Status = (EnumStatus)oReader.GetInt32("Status", (int)EnumStatus.Regardless); oOutsideDuty.CreatedBy = oReader.GetInt32("CreatedBy", 0); oOutsideDuty.CreatedDate = oReader.GetDateTime("CreatedDate", DateTime.MinValue); oOutsideDuty.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oOutsideDuty.ModifiedDate = oReader.GetDateTime("ModifiedDate", DateTime.MinValue); this.SetObjectState(oOutsideDuty, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { OutsideDuty oOutsideDuty = new OutsideDuty(); MapObject(oOutsideDuty, oReader); return oOutsideDuty as T; } protected OutsideDuty CreateObject(DataReader oReader) { OutsideDuty oOutsideDuty = new OutsideDuty(); MapObject(oOutsideDuty, oReader); return oOutsideDuty; } #region Service implementation public OutsideDuty Get(int id) { OutsideDuty oOutsideDuty = new OutsideDuty(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(OutsideDutyDA.Get(tc, id)); if (oreader.Read()) { oOutsideDuty = 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 oOutsideDuty; } public List Get() { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OutsideDutyDA.Get(tc)); var outsideDutys = this.CreateObjects(dr); dr.Close(); tc.End(); return outsideDutys; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List Get(EnumStatus status) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OutsideDutyDA.Get(tc, status)); var oOutsideDuties = this.CreateObjects(dr); dr.Close(); tc.End(); return oOutsideDuties; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int Save(OutsideDuty oOutsideDuty) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oOutsideDuty.IsNew) { int id = tc.GenerateID("OutsideDuty", "OutsideDutyID"); base.SetObjectID(oOutsideDuty, (id)); int seqNo = tc.GenerateID("OutsideDuty", "SequenceNO"); oOutsideDuty.Sequence = seqNo; OutsideDutyDA.Insert(tc, oOutsideDuty); } else { OutsideDutyDA.Update(tc, oOutsideDuty); } tc.End(); return oOutsideDuty.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); OutsideDutyDA.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 } #endregion }