using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.Model; using Payroll.BO; using Ease.CoreV35.DataAccess; namespace Payroll.Service { public class EmployeeRetirementService : ServiceTemplate, Payroll.BO.EmployeeRetirement.IEmployeeRetirementService { private void MapObject(EmployeeRetirement oemp, DataReader oReader) { base.SetObjectID(oemp, oReader.GetID("empretirementid")); oemp.retirementAge = oReader.GetInt32("RetirementAge").Value; oemp.employeeID = ID.FromInteger(oReader.GetInt32("employeeID").Value); } protected override T CreateObject(DataReader oReader) { EmployeeRetirement oemp = new EmployeeRetirement(); MapObject(oemp, oReader); return oemp as T; } protected EmployeeRetirement CreateObject(DataReader oReader) { EmployeeRetirement oemp = new EmployeeRetirement(); MapObject(oemp, oReader); return oemp; } #region function public ObjectsTemplate Get() { ObjectsTemplate empRetirement = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmployeeRetirementDA.Get(tc)); empRetirement = 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 } return empRetirement; } #endregion #region IEmployeeRetirementService Members public ID Save(EmployeeRetirement oEmployee) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oEmployee.IsNew) { int id = tc.GenerateID("EmployeeRetirement", "empretirementid"); base.SetObjectID(oEmployee, ID.FromInteger(id)); EmployeeRetirementDA.Insert(tc, oEmployee); } else { EmployeeRetirementDA.Update(tc, oEmployee); } tc.End(); return oEmployee.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void SaveAll(ObjectsTemplate items) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (EmployeeRetirement iteam in items) { int id = tc.GenerateID("EmployeeRetirement", "empretirementid"); base.SetObjectID(iteam, ID.FromInteger(id)); EmployeeRetirementDA.Insert(tc, iteam); } 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 UpdateAll(ObjectsTemplate items) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (EmployeeRetirement iteam in items) { EmployeeRetirementDA.Update(tc, iteam); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int GetById(ID id) { TransactionContext tc = null; int reAge = -1; try { tc = TransactionContext.Begin(true); reAge = EmployeeRetirementDA.GetAgeById(tc, id); if (reAge != -1) return reAge; tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return reAge; } #endregion } }