using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.DataAccess; using Payroll.BO; using Ease.CoreV35.Caching; namespace Payroll.Service { #region PLDailyInterest Service [Serializable] public class PLDailyInterestService : ServiceTemplate, IPLDailyInterestService { #region Private functions and declaration Cache _cache = new Cache(typeof(PLDailyInterest)); #endregion public PLDailyInterestService() { } private void MapObject(PLDailyInterest oInt, DataReader oReader) { base.SetObjectID(oInt, oReader.GetID("PLDailyInterestID")); oInt.InterestDate = oReader.GetDateTime("InterestDate").Value; oInt.DailyRate = oReader.GetDouble("DailyRate").Value; oInt.AnnualRate = oReader.GetDouble("AnnualRate").Value; this.SetObjectState(oInt, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { PLDailyInterest oInt = new PLDailyInterest(); MapObject(oInt, oReader); return oInt as T; } protected PLDailyInterest CreateObject(DataReader oReader) { PLDailyInterest oInt = new PLDailyInterest(); MapObject(oInt, oReader); return oInt; } #region Service implementation public ObjectsTemplate Get(DateTime FrominterestDate, DateTime ToIntDate) { #region Cache Header ObjectsTemplate oInt = _cache["Get", FrominterestDate, ToIntDate] as ObjectsTemplate; if (oInt != null) return oInt; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(PLDailyInterestDA.Get(tc, FrominterestDate, ToIntDate)); oInt = 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(oInt, "Get", FrominterestDate, ToIntDate); #endregion return oInt; } public PLDailyInterest Get(DateTime issueDate) { PLDailyInterest oInt = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(PLDailyInterestDA.Get(tc,issueDate)); if(dr.Read()) oInt = this.CreateObject(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 } return oInt; } public ID Save(DateTime FrominterestDate, DateTime ToIntDate,ObjectsTemplate oItems) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); this.Delete(FrominterestDate, ToIntDate); foreach(PLDailyInterest oItem in oItems) { int id = tc.GenerateID("PLDailyInterest", "PLDailyInterestID"); base.SetObjectID(oItem, ID.FromInteger(id)); PLDailyInterestDA.Insert(tc, oItem); } tc.End(); return oItems[0].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(DateTime FrominterestDate, DateTime ToIntDate) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); PLDailyInterestDA.Delete(tc, FrominterestDate, ToIntDate); 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 }