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 CRGDepartmentLookup Service [Serializable] public class CRGDepartmentLookupService : ServiceTemplate, ICRGDepartmentLookupService { #region Private functions and declaration Cache _cache = new Cache(typeof(CRGDepartmentLookup)); #endregion public CRGDepartmentLookupService() { } private void MapObject(CRGDepartmentLookup oCRGDepartmentLookup, DataReader oReader) { base.SetObjectID(oCRGDepartmentLookup, oReader.GetID("CRGDepartmentLookupID")); oCRGDepartmentLookup.CrgID = oReader.GetID("CrgID"); oCRGDepartmentLookup.DepartmentID = oReader.GetID("DepartmentID"); this.SetObjectState(oCRGDepartmentLookup, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { CRGDepartmentLookup oCRGDepartmentLookup = new CRGDepartmentLookup(); MapObject(oCRGDepartmentLookup, oReader); return oCRGDepartmentLookup as T; } protected CRGDepartmentLookup CreateObject(DataReader oReader) { CRGDepartmentLookup oCRGDepartmentLookup = new CRGDepartmentLookup(); MapObject(oCRGDepartmentLookup, oReader); return oCRGDepartmentLookup; } #region Service implementation public CRGDepartmentLookup Get(ID id) { CRGDepartmentLookup oCRGDepartmentLookup = new CRGDepartmentLookup(); #region Cache Header oCRGDepartmentLookup = _cache["Get", id] as CRGDepartmentLookup; if (oCRGDepartmentLookup != null) return oCRGDepartmentLookup; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(CRGDepartmentLookupDA.Get(tc, id)); if (oreader.Read()) { oCRGDepartmentLookup = 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(oCRGDepartmentLookup, "Get", id); #endregion return oCRGDepartmentLookup; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate oCDLookups = _cache["Get"] as ObjectsTemplate; if (oCDLookups != null) return oCDLookups; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(CRGDepartmentLookupDA.Get(tc)); oCDLookups = 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(oCDLookups, "Get"); #endregion return oCDLookups; } public ID Save(CRGDepartmentLookup oCRGDepartmentLookup) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oCRGDepartmentLookup.IsNew) { int id = tc.GenerateID("CRGDepartmentLookup", "CRGDepartmentLookupID"); base.SetObjectID(oCRGDepartmentLookup, ID.FromInteger(id)); CRGDepartmentLookupDA.Insert(tc, oCRGDepartmentLookup); } else { CRGDepartmentLookupDA.Update(tc, oCRGDepartmentLookup); } tc.End(); return oCRGDepartmentLookup.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Save(ObjectsTemplate oCDLookups) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ObjectsTemplate deleteLookUp = new ObjectsTemplate(); DataReader dr = new DataReader(CRGDepartmentLookupDA.Get(tc)); deleteLookUp = this.CreateObjects(dr); dr.Close(); if (deleteLookUp.Count > 0) { CRGDepartmentLookupDA.Delete(tc); } foreach (CRGDepartmentLookup lookUp in oCDLookups) { this.SetObjectState(lookUp, ObjectState.New); if (lookUp.IsNew) { int id = tc.GenerateID("CRGDepartmentLookup", "CRGDepartmentLookupID"); base.SetObjectID(lookUp, ID.FromInteger(id)); CRGDepartmentLookupDA.Insert(tc, lookUp); } else { CRGDepartmentLookupDA.Update(tc, lookUp); } } tc.End(); } 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); CRGDepartmentLookupDA.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 }