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 TrainingScheduleStatusService : ServiceTemplate, ITrainingScheduleStatusService { #region Object private void MapObject(TrainingScheduleStatus oTrainingScheduleStatus, DataReader oReader) { base.SetObjectID(oTrainingScheduleStatus, oReader.GetInt32("TRAININGSCHEDULESTATUSID").Value); oTrainingScheduleStatus.Name = oReader.GetString("Name"); oTrainingScheduleStatus.Sequence = oReader.GetInt32("SEQUENCENO").Value; oTrainingScheduleStatus.Status = (EnumStatus)oReader.GetInt32("STATUS").Value; oTrainingScheduleStatus.CreatedBy = oReader.GetInt32("CreatedBy", 0); oTrainingScheduleStatus.CreatedDate = oReader.GetDateTime("CreationDate").Value; oTrainingScheduleStatus.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oTrainingScheduleStatus.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oTrainingScheduleStatus, Ease.Core.ObjectState.Saved); } #region Overrides of ServiceTemplate protected override T CreateObject(DataReader dr) { TrainingScheduleStatus oTrainingScheduleStatus = new TrainingScheduleStatus(); MapObject(oTrainingScheduleStatus, dr); return oTrainingScheduleStatus as T; } #endregion #endregion #region Implementation of ITrainingScheduleStatusService public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); TrainingScStatusDA.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 } } public int Save(TrainingScheduleStatus oTrainingScheduleStatus) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oTrainingScheduleStatus.IsNew) { int id = tc.GenerateID("TRAININGSCHEDULESTATUS", "TRAININGSCHEDULESTATUSID"); base.SetObjectID(oTrainingScheduleStatus, id); TrainingScStatusDA.Insert(tc, oTrainingScheduleStatus); } else { TrainingScStatusDA.Update(tc, oTrainingScheduleStatus); } tc.End(); return oTrainingScheduleStatus.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List Get() { List trainingStatusses = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(TrainingScStatusDA.Get(tc)); trainingStatusses = 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 trainingStatusses; } public TrainingScheduleStatus Get(int id) { TrainingScheduleStatus oTrainingScheduleStatus = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingScStatusDA.Get(tc, id)); if (oreader.Read()) { oTrainingScheduleStatus = 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 oTrainingScheduleStatus; } public List Get(EnumStatus status) { List trainingScheduleStatuses = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(TrainingScStatusDA.Get(tc, status)); trainingScheduleStatuses = 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 trainingScheduleStatuses; } #endregion } }