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 JVSetupDetail Service [Serializable] public class JVSetupDetailService : ServiceTemplate, IJVSetupDetailService { #region Private functions and declaration Cache _cache = new Cache(typeof(JVSetupDetail)); public JVSetupDetailService() { } private void MapObject(JVSetupDetail oJVSetupDetail, DataReader oReader) { base.SetObjectID(oJVSetupDetail, ID.FromInteger(oReader.GetInt32("JVSetupDetailID").Value)); oJVSetupDetail.ItemID = oReader.GetString("ItemID") == null ? null : ID.FromInteger(oReader.GetInt32("ItemID").Value); oJVSetupDetail.JVItemType = (enumPayrollComponentType)oReader.GetInt32("JVItemType").Value; oJVSetupDetail.JVSetupID = oReader.GetString("JVSetupID") == null ? null : ID.FromInteger(oReader.GetInt32("JVSetupID").Value); oJVSetupDetail.Name = oReader.GetString("Name"); this.SetObjectState(oJVSetupDetail, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { JVSetupDetail oJVSetupDetail = new JVSetupDetail(); MapObject(oJVSetupDetail, oReader); return oJVSetupDetail as T; } protected JVSetupDetail CreateObject(DataReader oReader) { JVSetupDetail oJVSetupDetail = new JVSetupDetail(); MapObject(oJVSetupDetail, oReader); return oJVSetupDetail; } #endregion #region Service implementation public JVSetupDetail Get(ID id) { JVSetupDetail oJVSetupDetail = new JVSetupDetail(); #region Cache Header oJVSetupDetail = (JVSetupDetail)_cache["Get", id]; if (oJVSetupDetail != null) return oJVSetupDetail; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(JVSetupDetailDA.Get(tc, id)); if (oreader.Read()) { oJVSetupDetail = 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(oJVSetupDetail, "Get", id); #endregion return oJVSetupDetail; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate oJVSetupDetails = _cache["Get"] as ObjectsTemplate; if (oJVSetupDetails != null) return oJVSetupDetails; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(JVSetupDetailDA.Get(tc)); oJVSetupDetails = this.CreateObjects(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(oJVSetupDetails, "Get"); #endregion return oJVSetupDetails; } public ObjectsTemplate GetByJVSetup(ID JVSetupID) { #region Cache Header ObjectsTemplate JVSetupDetails = _cache["GetByJVSetup", JVSetupID] as ObjectsTemplate; if (JVSetupDetails != null) return JVSetupDetails; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(JVSetupDetailDA.GetByJVSetup(tc, JVSetupID)); JVSetupDetails = 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(JVSetupDetails, "GetByJVSetup", JVSetupID); #endregion return JVSetupDetails; } public ID Save(JVSetupDetail oJVSetupDetail) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oJVSetupDetail.IsNew) { int id = tc.GenerateID("JVSetupDetail", "JVSetupDetailID"); base.SetObjectID(oJVSetupDetail, ID.FromInteger(id)); JVSetupDetailDA.Insert(tc, oJVSetupDetail); } else { JVSetupDetailDA.Update(tc, oJVSetupDetail); } return oJVSetupDetail.ID; tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetJVSetupDetail", e); #endregion } } public void Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); JVSetupDetailDA.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 }