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 { [Serializable] public class LeaveExceptionService : ServiceTemplate, ILeaveExceptionService { #region Private functions and declaration Cache _cache = new Cache(typeof(LeaveException)); public LeaveExceptionService() { } private void MapObject(LeaveException oLeaveException, DataReader oReader) { base.SetObjectID(oLeaveException, oReader.GetID("LeaveExceptionID")); oLeaveException.EmployeeID = oReader.GetInt32("EmployeeID").Value; oLeaveException.StartDate = oReader.GetDateTime("StartDate").Value; oLeaveException.EndDate = oReader.GetDateTime("EndDate").Value; oLeaveException.LeaveID = oReader.GetInt16("LeaveID").Value; oLeaveException.OpeningBalance = oReader.GetDouble("OpeningBalance").Value; oLeaveException.MaxDays = oReader.GetDouble("MaxDays").Value; oLeaveException.CFDays = oReader.GetDouble("CFDays").Value; this.SetObjectState(oLeaveException, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { LeaveException oLeave = new LeaveException(); MapObject(oLeave, oReader); return oLeave as T; } private LeaveException CreateObject(DataReader oReader) { LeaveException oLeave = new LeaveException(); MapObject(oLeave, oReader); return oLeave; } #endregion public ObjectsTemplate Get(DateTime dFrom, DateTime dTo) { #region Cache Header ObjectsTemplate oLeaves = _cache["Get"] as ObjectsTemplate; if (oLeaves != null) return oLeaves; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LeaveExceptionDA.Get2(tc, dFrom, dTo)); oLeaves = 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(oLeaves, "Get"); #endregion return oLeaves; } public ObjectsTemplate GetByEmpID(int nLeaveID,int nEmpID) { #region Cache Header ObjectsTemplate oLeaves = _cache["GetByEmpID"] as ObjectsTemplate; if (oLeaves != null) return oLeaves; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LeaveExceptionDA.GetByEmpID(tc, nLeaveID,nEmpID)); oLeaves = 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(oLeaves, "GetByEmpID"); #endregion return oLeaves; } public ID Save(LeaveException oLeave) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); LeaveExceptionDA.Insert(tc, oLeave); tc.End(); return oLeave.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); //throw new ServiceException("Failed to Get Leave", e); throw new Exception("Failed to Save Leave. Because " + e.Message, e); #endregion } } public void DeleteItem(int nID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); LeaveExceptionDA.DeleteItem(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 } } public void DeleteByLeaveID(int nLeaveID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); LeaveExceptionDA.Delete(tc, nLeaveID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } } }