using System; using System.Data; using System.Linq; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Payroll.BO; using Ease.CoreV35.Caching; namespace Payroll.Service { #region class NominationPurposeService [Serializable] public class NominationPurposeService : ServiceTemplate, INominationPurposeService { #region Private functions and declaration Cache _cache = new Cache(typeof(NominationPurpose)); #endregion #region constructor public NominationPurposeService() { } #endregion #region Object private void MapObject(NominationPurpose oNominationPurpose, DataReader oReader) { base.SetObjectID(oNominationPurpose, oReader.GetID("NOMINATIONPURPOSEID")); oNominationPurpose.Code = oReader.GetString("CODE"); oNominationPurpose.Description = oReader.GetString("DESCRIPTION"); oNominationPurpose.Sequence = oReader.GetInt32("SequenceNo").Value; oNominationPurpose.Status = (EnumStatus)oReader.GetInt32("Status").Value; oNominationPurpose.CreatedBy = oReader.GetID("CreatedBy"); oNominationPurpose.CreatedDate = oReader.GetDateTime("CreationDate").Value; oNominationPurpose.ModifiedBy = oReader.GetID("ModifiedBy"); oNominationPurpose.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oNominationPurpose, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { NominationPurpose oNominationPurpose = new NominationPurpose(); MapObject(oNominationPurpose, oReader); return oNominationPurpose as T; } protected NominationPurpose CreateObject(DataReader oReader) { NominationPurpose oNominationPurpose = new NominationPurpose(); MapObject(oNominationPurpose, oReader); return oNominationPurpose; } #endregion #region Service implementation public NominationPurpose Get(ID id) { NominationPurpose oNominationPurpose = new NominationPurpose(); #region Cache Header oNominationPurpose = _cache["Get", id] as NominationPurpose; if (oNominationPurpose != null) return oNominationPurpose; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(NominationPurposeDA.Get(tc, id)); if (oreader.Read()) { oNominationPurpose = 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(oNominationPurpose, "Get", id); #endregion return oNominationPurpose; } public NominationPurpose Get(string sCode) { NominationPurpose oNominationPurpose = new NominationPurpose(); #region Cache Header oNominationPurpose = _cache["Get", sCode] as NominationPurpose; if (oNominationPurpose != null) return oNominationPurpose; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(NominationPurposeDA.Get(tc, sCode)); if (oreader.Read()) { oNominationPurpose = 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(oNominationPurpose, "Get", sCode); #endregion return oNominationPurpose; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate nominationPurposes = _cache["Get"] as ObjectsTemplate; if (nominationPurposes != null) return nominationPurposes; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(NominationPurposeDA.Get(tc)); nominationPurposes = 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(nominationPurposes, "Get"); #endregion return nominationPurposes; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate nominationPurposes = _cache["Get"] as ObjectsTemplate; if (nominationPurposes != null) return nominationPurposes; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(NominationPurposeDA.Get(tc, status)); nominationPurposes = 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(nominationPurposes, "Get", status); #endregion return nominationPurposes; } public ID Save(NominationPurpose oNominationPurpose) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oNominationPurpose.IsNew) { int id = tc.GenerateID("NOMINATIONPURPOSE", "NOMINATIONPURPOSEID"); base.SetObjectID(oNominationPurpose, ID.FromInteger(id)); NominationPurposeDA.Insert(tc, oNominationPurpose); } else { NominationPurposeDA.Update(tc, oNominationPurpose); } tc.End(); return oNominationPurpose.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); NominationPurposeDA.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 }