using System; using System.Data; using System.Linq; using Ease.Core; using Ease.Core.Model; using Ease.Core.DataAccess; using System.Collections.Generic; using HRM.BO; using Ease.Core.Utility; namespace HRM.DA { #region Punishment Service [Serializable] public class PunishmentService : ServiceTemplate, IPunishmentService { public PunishmentService() { } private void MapObject(Punishment oPunishment, DataReader oReader) { base.SetObjectID(oPunishment, oReader.GetInt32("PunishmentID").Value); oPunishment.Code = oReader.GetString("code"); oPunishment.Description = oReader.GetString("Description"); this.SetObjectState(oPunishment, Ease.Core.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(int id) { Punishment oPunishment = new Punishment(); 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 } return oPunishment; } public List Get() { #region List religions = new List(); //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 } return religions; } public List Get(EnumStatus status) { #region Cache Header List punishments = new List(); #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(PunishmentDA.Get(tc, status)); punishments = 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 punishments; } public List GetDAPunishmentPicker(int punishmentid) { List Punishments = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(PunishmentDA.GetDAPunishmentPicker(tc, punishmentid)); Punishments = 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 Punishments; } public int Save(Punishment oPunishment) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oPunishment.IsNew) { int id = tc.GenerateID("Punishment", "PunishmentID"); base.SetObjectID(oPunishment, 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(int 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 }