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