using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.Model; using Payroll.BO; using Ease.CoreV35.Caching; using Ease.CoreV35.DataAccess; using Payroll.Service.Attendence.DA; using Payroll.BO; namespace Payroll.Service.Attendence.Service { #region OutsideDuty Service [Serializable] public class OutsideDutyService : ServiceTemplate, IOutsideDutyService { #region Private functions and declaration Cache _cache = new Cache(typeof(OutsideDuty)); #endregion public OutsideDutyService() { } private void MapObject(OutsideDuty oOutsideDuty, DataReader oReader) { base.SetObjectID(oOutsideDuty, oReader.GetID("OutsideDutyID")); oOutsideDuty.Name = oReader.GetString("Name"); oOutsideDuty.Sequence = oReader.GetInt32("SequenceNo").Value; oOutsideDuty.Status = (EnumStatus)oReader.GetInt32("Status").Value; oOutsideDuty.CreatedBy = oReader.GetID("CreatedBy"); oOutsideDuty.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oOutsideDuty.ModifiedBy = oReader.GetID("ModifiedBy"); oOutsideDuty.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oOutsideDuty, Ease.CoreV35.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(ID id) { OutsideDuty oOutsideDuty = new OutsideDuty(); #region Cache Header oOutsideDuty = _cache["Get", id] as OutsideDuty; if (oOutsideDuty != null) return oOutsideDuty; #endregion 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 } #region Cache Footer _cache.Add(oOutsideDuty, "Get", id); #endregion return oOutsideDuty; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate outsideDutys = _cache["Get"] as ObjectsTemplate; if (outsideDutys != null) return outsideDutys; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OutsideDutyDA.Get(tc)); outsideDutys = 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 } #region Cache Footer _cache.Add(outsideDutys, "Get"); #endregion return outsideDutys; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate oOutsideDuties = _cache["Get"] as ObjectsTemplate; if (oOutsideDuties != null) return oOutsideDuties; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OutsideDutyDA.Get(tc, status)); oOutsideDuties = 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 } #region Cache Footer _cache.Add(oOutsideDuties, "Get", status); #endregion return oOutsideDuties; } public ID Save(OutsideDuty oOutsideDuty) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oOutsideDuty.IsNew) { int id = tc.GenerateID("OutsideDuty", "OutsideDutyID"); base.SetObjectID(oOutsideDuty, ID.FromInteger(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(ID 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 }