using System; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using Ease.Core.Utility; using System.Collections.Generic; namespace HRM.DA { public class NominationPurposeService : ServiceTemplate, INominationPurposeService { #region constructor public NominationPurposeService() { } #endregion #region Object private void MapObject(NominationPurpose oNominationPurpose, DataReader oReader) { base.SetObjectID(oNominationPurpose, oReader.GetInt32("NOMINATIONPURPOSEID").Value); 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.GetInt32("CreatedBy", 0); oNominationPurpose.CreatedDate = oReader.GetDateTime("CreationDate").Value; oNominationPurpose.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oNominationPurpose.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oNominationPurpose, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { NominationPurpose oNominationPurpose = new NominationPurpose(); MapObject(oNominationPurpose, oReader); return oNominationPurpose as T; } #endregion #region Service implementation public NominationPurpose Get(int id) { NominationPurpose oNominationPurpose = null; 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 } return oNominationPurpose; } public NominationPurpose Get(string sCode) { NominationPurpose oNominationPurpose = null; 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 } return oNominationPurpose; } public List Get() { List nominationPurposes = new List(); 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 } return nominationPurposes; } public List Get(EnumStatus status) { List nominationPurposes = new List(); 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 } return nominationPurposes; } public List GetListbyId(int id) { List nominationPurposes = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(NominationPurposeDA.Get(tc, id)); 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 } return nominationPurposes; } public int Save(NominationPurpose oNominationPurpose) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oNominationPurpose.IsNew) { int id = tc.GenerateID("NOMINATIONPURPOSE", "NOMINATIONPURPOSEID"); base.SetObjectID(oNominationPurpose, id); if (oNominationPurpose.Code == "") oNominationPurpose.Code = oNominationPurpose.ID.ToString(); 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(int 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 } }