using System; using Ease.CoreV35.Model; using Ease.CoreV35.DataAccess; using Payroll.BO; using Ease.CoreV35.Caching; namespace Payroll.Service { #region Class NatureOfTrainingService [Serializable] public class NatureOfTrainingService : ServiceTemplate, INatureOfTrainingService { #region Private functions and declaration Cache _cache = new Cache(typeof(NatureOfTraining)); #endregion #region Object private void MapObject(NatureOfTraining oNatureOfTraining, DataReader oReader) { base.SetObjectID(oNatureOfTraining, oReader.GetID("NATUREOFTRAININGID")); oNatureOfTraining.Code = oReader.GetString("CODE"); oNatureOfTraining.Name = oReader.GetString("NAME"); oNatureOfTraining.Sequence = oReader.GetInt32("SequenceNo").Value; oNatureOfTraining.Status = (EnumStatus)oReader.GetInt32("Status").Value; oNatureOfTraining.CreatedBy = oReader.GetID("CreatedBy"); oNatureOfTraining.CreatedDate = oReader.GetDateTime("CreationDate").Value; oNatureOfTraining.ModifiedBy = oReader.GetID("ModifiedBy"); oNatureOfTraining.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oNatureOfTraining, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { NatureOfTraining oNatureOfTraining = new NatureOfTraining(); MapObject(oNatureOfTraining, oReader); return oNatureOfTraining as T; } protected NatureOfTraining CreateObject(DataReader oReader) { NatureOfTraining oNatureOfTraining = new NatureOfTraining(); MapObject(oNatureOfTraining, oReader); return oNatureOfTraining; } #endregion #region Service implementation public NatureOfTraining Get(ID id) { NatureOfTraining oNatureOfTraining = new NatureOfTraining(); #region Cache Header oNatureOfTraining = _cache["Get", id] as NatureOfTraining; if (oNatureOfTraining != null) return oNatureOfTraining; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(NatureOfTrainingDA.Get(tc, id)); if (oreader.Read()) { oNatureOfTraining = 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(oNatureOfTraining, "Get", id); #endregion return oNatureOfTraining; } public NatureOfTraining Get(string sCode) { NatureOfTraining oNatureOfTraining = new NatureOfTraining(); #region Cache Header oNatureOfTraining = _cache["Get", sCode] as NatureOfTraining; if (oNatureOfTraining != null) return oNatureOfTraining; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(NatureOfTrainingDA.Get(tc, sCode)); if (oreader.Read()) { oNatureOfTraining = 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(oNatureOfTraining, "Get", sCode); #endregion return oNatureOfTraining; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate natureOfTrainings = _cache["Get"] as ObjectsTemplate; if (natureOfTrainings != null) return natureOfTrainings; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(NatureOfTrainingDA.Get(tc)); natureOfTrainings = 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(natureOfTrainings, "Get"); #endregion return natureOfTrainings; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate natureOfTrainings = _cache["Get"] as ObjectsTemplate; if (natureOfTrainings != null) return natureOfTrainings; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(NatureOfTrainingDA.Get(tc, status)); natureOfTrainings = 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(natureOfTrainings, "Get", status); #endregion return natureOfTrainings; } public ID Save(NatureOfTraining oNatureOfTraining) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oNatureOfTraining.IsNew) { int id = tc.GenerateID("NATUREOFTRAINING", "NATUREOFTRAININGID"); base.SetObjectID(oNatureOfTraining, ID.FromInteger(id)); NatureOfTrainingDA.Insert(tc, oNatureOfTraining); } else { NatureOfTrainingDA.Update(tc, oNatureOfTraining); } tc.End(); return oNatureOfTraining.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(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); NatureOfTrainingDA.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 }