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 Punishment Service [Serializable] public class PunishmentService : ServiceTemplate, IPunishmentService { #region Private functions and declaration Cache _cache = new Cache(typeof(Punishment)); #endregion public PunishmentService() { } private void MapObject(Punishment oPunishment, DataReader oReader) { base.SetObjectID(oPunishment, oReader.GetID("PunishmentID")); oPunishment.Code = oReader.GetString("code"); oPunishment.Description = oReader.GetString("Description"); this.SetObjectState(oPunishment, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Punishment oPunishment = new Punishment(); MapObject(oPunishment, oReader); return oPunishment as T; } protected Punishment CreateObject(DataReader oReader) { Punishment oPunishment = new Punishment(); MapObject(oPunishment, oReader); return oPunishment; } #region Service implementation public Punishment Get(ID id) { Punishment oPunishment = new Punishment(); #region Cache Header oPunishment = _cache["Get", id] as Punishment; if (oPunishment != null) return oPunishment; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PunishmentDA.Get(tc, id)); if (oreader.Read()) { oPunishment = 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(oPunishment, "Get", id); #endregion return oPunishment; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate religions = _cache["Get"] as ObjectsTemplate; if (religions != null) return religions; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(PunishmentDA.Get(tc)); religions = 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(religions, "Get"); #endregion return religions; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate religions = _cache["Get"] as ObjectsTemplate; if (religions != null) return religions; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(PunishmentDA.Get(tc, status)); religions = 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(religions, "Get", status); #endregion return religions; } public ID Save(Punishment oPunishment) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oPunishment.IsNew) { int id = tc.GenerateID("Punishment", "PunishmentID"); base.SetObjectID(oPunishment, ID.FromInteger(id)); PunishmentDA.Insert(tc, oPunishment); } else { PunishmentDA.Update(tc, oPunishment); } tc.End(); return oPunishment.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); PunishmentDA.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 }