using System; using Ease.CoreV35.Caching; using Ease.CoreV35.DataAccess; using Ease.CoreV35.Model; using Payroll.BO; namespace Payroll.Service { #region Class TrainingScheduleStatus Service [Serializable] public class TrainingScheduleStatusService : ServiceTemplate, ITrainingScheduleStatusService { #region Private functions and declaration Cache _cache = new Cache(typeof(TrainingScheduleStatus)); #endregion #region Object private void MapObject(TrainingScheduleStatus oTrainingScheduleStatus, DataReader oReader) { base.SetObjectID(oTrainingScheduleStatus, oReader.GetID("TRAININGSCHEDULESTATUSID")); oTrainingScheduleStatus.Name = oReader.GetString("Name"); oTrainingScheduleStatus.Sequence = oReader.GetInt32("SEQUENCENO").Value; oTrainingScheduleStatus.Status = (EnumStatus)oReader.GetInt32("STATUS").Value; oTrainingScheduleStatus.CreatedBy = oReader.GetID("CREATEDBY"); oTrainingScheduleStatus.CreatedDate = oReader.GetDateTime("CREATIONDATE").Value; oTrainingScheduleStatus.ModifiedBy = oReader.GetID("MODIFIEDBY"); oTrainingScheduleStatus.ModifiedDate = oReader.GetDateTime("MODIFIEDDATE"); this.SetObjectState(oTrainingScheduleStatus, Ease.CoreV35.ObjectState.Saved); } #region Overrides of ServiceTemplate protected override T CreateObject(DataReader dr) { TrainingScheduleStatus oTrainingScheduleStatus = new TrainingScheduleStatus(); MapObject(oTrainingScheduleStatus, dr); return oTrainingScheduleStatus as T; } #endregion protected TrainingScheduleStatus CreateObject(DataReader oReader) { TrainingScheduleStatus oTrainingScheduleStatus = new TrainingScheduleStatus(); MapObject(oTrainingScheduleStatus, oReader); return oTrainingScheduleStatus; } #endregion #region Implementation of ITrainingScheduleStatusService public void Delete(ID 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 ID Save(TrainingScheduleStatus oTrainingScheduleStatus) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oTrainingScheduleStatus.IsNew) { int id = tc.GenerateID("TRAININGSCHEDULESTATUS", "TRAININGSCHEDULESTATUSID"); base.SetObjectID(oTrainingScheduleStatus, ID.FromInteger(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 ObjectsTemplate Get() { #region Cache Header ObjectsTemplate trainingStatusses = _cache["Get"] as ObjectsTemplate; if (trainingStatusses != null) return trainingStatusses; #endregion 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 } #region Cache Footer _cache.Add(trainingStatusses, "Get"); #endregion return trainingStatusses; } public TrainingScheduleStatus Get(ID id) { TrainingScheduleStatus oTrainingScheduleStatus = new TrainingScheduleStatus(); #region Cache Header oTrainingScheduleStatus = _cache["Get", id] as TrainingScheduleStatus; if (oTrainingScheduleStatus != null) return oTrainingScheduleStatus; #endregion 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 } #region Cache Footer _cache.Add(oTrainingScheduleStatus, "Get", id); #endregion return oTrainingScheduleStatus; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate trainingScheduleStatuses = _cache["Get"] as ObjectsTemplate; if (trainingScheduleStatuses != null) return trainingScheduleStatuses; #endregion 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 } #region Cache Footer _cache.Add(trainingScheduleStatuses, "Get", status); #endregion return trainingScheduleStatuses; } #endregion } #endregion }