using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35; using Ease.CoreV35.Caching; using Ease.CoreV35.DataAccess; using Ease.CoreV35.Model; using Payroll.BO; namespace Payroll.Service { [Serializable] public class BudgetGradeService : ServiceTemplate, IBudgetGradeService { #region Private functions and declaration Cache _cache = new Cache(typeof(BudgetGrade)); #endregion #region Object Mapping private void MapObject(BudgetGrade oBudgetGrade, DataReader oReader) { SetObjectID(oBudgetGrade, oReader.GetID("BudgetGradeID")); oBudgetGrade.BudgetID = oReader.GetID("BudgetID"); oBudgetGrade.ChangedPercentage = oReader.GetDouble("ChangedPercentage").Value; oBudgetGrade.FixedAmount = oReader.GetDouble("FixedAmount").Value; oBudgetGrade.GradeID = oReader.GetID("GradeID"); SetObjectState(oBudgetGrade, ObjectState.Saved); } protected override T CreateObject(DataReader dr) { BudgetGrade oBudgetGrade = new BudgetGrade(); MapObject(oBudgetGrade, dr); return oBudgetGrade as T; } #endregion #region Service Implementation public BudgetGrade Get(ID nID) { BudgetGrade oBudgetGrade = new BudgetGrade(); #region Cache Header oBudgetGrade = _cache["Get", nID] as BudgetGrade; if (oBudgetGrade != null) return oBudgetGrade; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(BudgetGradeDA.Get(tc, nID)); if (oreader.Read()) { oBudgetGrade = 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(oBudgetGrade, "Get", nID); #endregion return oBudgetGrade; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate oBudgetGrades = _cache["Get"] as ObjectsTemplate; if (oBudgetGrades != null) return oBudgetGrades; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(BudgetGradeDA.Get(tc)); // if (oreader.Read()) //{ oBudgetGrades = 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(oBudgetGrades, "Get"); #endregion return oBudgetGrades; } public ObjectsTemplate Get(int nBudID) { #region Cache Header ObjectsTemplate oBudgetGrades = _cache["Get"] as ObjectsTemplate; if (oBudgetGrades != null) return oBudgetGrades; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(BudgetGradeDA.Get(tc,nBudID)); // if (oreader.Read()) //{ oBudgetGrades = 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(oBudgetGrades, "Get"); #endregion return oBudgetGrades; } public ID Save(BudgetGrade item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (item.IsNew) { int id = tc.GenerateID("BudgetGrade", "BudgetGradeID"); SetObjectID(item, ID.FromInteger(id)); BudgetGradeDA.Insert(tc, item); } else { BudgetGradeDA.Update(tc, item); } tc.End(); return item.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public ID Save(BudgetGrade item,TransactionContext tc) { try { int id = tc.GenerateID("BudgetGrade", "BudgetGradeID"); SetObjectID(item, ID.FromInteger(id)); BudgetGradeDA.Insert(tc, item); return item.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 nID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); BudgetGradeDA.Delete(tc, nID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion } }