using System; using System.Collections.Generic; using System.Linq; using System.Text; using Payroll.BO; using Ease.CoreV35.Model; using Ease.CoreV35.DataAccess; using Ease.CoreV35.Caching; namespace Payroll.Service { [Serializable] public class GrossDefinationService : ServiceTemplate, IGrossDefinationService { Cache _cache = new Cache(typeof(GrossDefination)); #region Private and Protected functions private void MapObject(GrossDefination oGrossDefination, DataReader oReader) { base.SetObjectID(oGrossDefination, oReader.GetID("GrossDefinationID")); oGrossDefination.SalaryComponentType =(EnumSalaryComponent)oReader.GetInt32("SalaryComponentType").Value; oGrossDefination.ComponentID = oReader.GetID("ComponentID"); oGrossDefination.Quantity = oReader.GetInt32("Quantity").Value; oGrossDefination.Description = oReader.GetString("Description"); oGrossDefination.BenefitDefinationType = (EnumBenefitDefinationType)oReader.GetInt32("BenefitDefinationType").Value; oGrossDefination.CreatedBy = oReader.GetID("CreatedBy"); oGrossDefination.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oGrossDefination.ModifiedBy = oReader.GetID("ModifiedBy"); oGrossDefination.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oGrossDefination, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { GrossDefination oGrossDefination = new GrossDefination(); MapObject(oGrossDefination, oReader); return oGrossDefination as T; } protected GrossDefination CreateObject(DataReader oReader) { GrossDefination oGrossDefination = new GrossDefination(); MapObject(oGrossDefination, oReader); return oGrossDefination; } #endregion Private and Protected functions #region IGrossDefinationService Members #region Get methods public GrossDefination Get(ID id) { GrossDefination oGrossDefination = new GrossDefination(); #region Cache Header oGrossDefination = _cache["Get", id] as GrossDefination; if (oGrossDefination != null) return oGrossDefination; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(GrossDefinationDA.Get(tc, id)); if (oreader.Read()) { oGrossDefination = 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(oGrossDefination, "Get", id); #endregion return oGrossDefination; } public ObjectsTemplate Get() { ObjectsTemplate oGrossDefinationColl = new ObjectsTemplate(); #region Cache Header //oGrossDefinationColl = _cache["Get"] as ObjectsTemplate; //if (oGrossDefinationColl != null) // return oGrossDefinationColl; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(GrossDefinationDA.Get(tc)); while (oreader.Read()) { GrossDefination oGrossDefination = new GrossDefination(); oGrossDefination = this.CreateObject(oreader); oGrossDefinationColl.Add(oGrossDefination); } 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(oGrossDefinationColl, "Get"); #endregion return oGrossDefinationColl; } public ObjectsTemplate Get(EnumBenefitDefinationType type) { ObjectsTemplate oGrossDefinationColl = new ObjectsTemplate(); #region Cache Header //oGrossDefinationColl = _cache["Get"] as ObjectsTemplate; //if (oGrossDefinationColl != null) // return oGrossDefinationColl; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(GrossDefinationDA.Get(tc, type)); while (oreader.Read()) { GrossDefination oGrossDefination = new GrossDefination(); oGrossDefination = this.CreateObject(oreader); oGrossDefinationColl.Add(oGrossDefination); } 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(oGrossDefinationColl, "Get"); #endregion return oGrossDefinationColl; } #endregion Get methods #region Save methods public void Save(GrossDefination grossDefination) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (grossDefination.IsNew) { int id = tc.GenerateID("GrossDefination", "GrossDefinationID"); base.SetObjectID(grossDefination, ID.FromInteger(id)); grossDefination.CreatedBy = User.CurrentUser.ID; //grossDefination.CreatedDate = GlobalFunctionDA.GetOperationDate(tc); grossDefination.CreatedDate = DateTime.Now; GrossDefinationDA.Save(tc, grossDefination); } else if (grossDefination.IsModified) { grossDefination.ModifiedBy = User.CurrentUser.ID; //grossDefination.ModifiedDate = GlobalFunctionDA.GetOperationDate(tc); grossDefination.ModifiedDate = DateTime.Now; GrossDefinationDA.Update(tc, grossDefination); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion Save methods] #region Delete methods public void Delete(ID grossDefinationID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); GrossDefinationDA.Delete(tc, grossDefinationID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion Delete methods #endregion IGrossDefinationService Members } }