using HRM.BO; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using System; using System.Collections.Generic; namespace HRM.DA { #region Function Service public class FunctionService : ServiceTemplate { public FunctionService() { } private void MapObject(Function oFunction, DataReader oReader) { base.SetObjectID(oFunction, oReader.GetInt32("FunctionID").Value); oFunction.Code = oReader.GetString("code"); oFunction.Name = oReader.GetString("description"); oFunction.Sequence = oReader.GetInt32("SequenceNo").Value; oFunction.Status = (EnumStatus)oReader.GetInt32("Status").Value; oFunction.CreatedBy = oReader.GetInt32("CreatedBy", 0); oFunction.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oFunction.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oFunction.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oFunction, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Function oFunction = new Function(); MapObject(oFunction, oReader); return oFunction as T; } #region Service implementation public Function Get(int id) { Function oFunction = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(FunctionDA.Get(tc, id)); if (oreader.Read()) { oFunction = 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 oFunction; } public Function Get(TransactionContext tc, int id) { Function oFunction = null; try { DataReader oreader = new DataReader(FunctionDA.Get(tc, id)); if (oreader.Read()) { oFunction = this.CreateObject(oreader); } oreader.Close(); } catch (Exception e) { #region Handle Exception ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oFunction; } public Function Get(string code) { Function oFunction = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(FunctionDA.Get(tc, code)); if (oreader.Read()) { oFunction = 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 oFunction; } public List Get(EnumStatus status) { List Functions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FunctionDA.Get(tc, status)); Functions = 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 Functions; } public int Save(Function oFunction) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oFunction.IsNew) { int id = tc.GenerateID("[Function]", "FunctionID"); base.SetObjectID(oFunction, id); int seqNo = tc.GenerateID("[Function]", "SequenceNo"); oFunction.Sequence = seqNo; FunctionDA.Insert(tc, oFunction); } else { FunctionDA.Update(tc, oFunction); } tc.End(); return oFunction.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, int UserID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); FunctionDA.Delete(tc, id, UserID); 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 }