using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.Model; using Payroll.BO; using Ease.CoreV35.Caching; using Ease.CoreV35.DataAccess; using Payroll.Service.Attendence.DA; namespace Payroll.Service.Attendence.Service { #region EmployeeOutsideDuty Service [Serializable] public class EmployeeOutsideDutyService : ServiceTemplate, IEmployeeOutsideDutyService { #region Private functions and declaration Cache _cache = new Cache(typeof(EmployeeOutsideDuty)); #endregion public EmployeeOutsideDutyService() { } private void MapObject(EmployeeOutsideDuty oEmployeeOutsideDuty, DataReader oReader) { base.SetObjectID(oEmployeeOutsideDuty, oReader.GetID("EmployeeOutsideDutyID")); oEmployeeOutsideDuty.EmployeeID = oReader.GetID("EmployeeID"); oEmployeeOutsideDuty.EntryDate = oReader.GetDateTime("EntryDate").Value; oEmployeeOutsideDuty.StartDate = oReader.GetDateTime("StartDate").Value; oEmployeeOutsideDuty.EndDate = oReader.GetDateTime("EndDate").Value; oEmployeeOutsideDuty.Comments = oReader.GetString("Comments"); //oEmployeeOutsideDuty.ShiftID = oReader.GetID("ShiftID"); oEmployeeOutsideDuty.OutsideDutyID = oReader.GetID("OutsideDutyID"); oEmployeeOutsideDuty.CreatedBy = oReader.GetID("CreatedBy"); oEmployeeOutsideDuty.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oEmployeeOutsideDuty.ModifiedBy = oReader.GetID("ModifiedBy"); oEmployeeOutsideDuty.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oEmployeeOutsideDuty, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { EmployeeOutsideDuty oEmployeeOutsideDuty = new EmployeeOutsideDuty(); MapObject(oEmployeeOutsideDuty, oReader); return oEmployeeOutsideDuty as T; } protected EmployeeOutsideDuty CreateObject(DataReader oReader) { EmployeeOutsideDuty oEmployeeOutsideDuty = new EmployeeOutsideDuty(); MapObject(oEmployeeOutsideDuty, oReader); return oEmployeeOutsideDuty; } #region Service implementation public EmployeeOutsideDuty Get(ID id) { EmployeeOutsideDuty oEmployeeOutsideDuty = new EmployeeOutsideDuty(); #region Cache Header oEmployeeOutsideDuty = _cache["Get", id] as EmployeeOutsideDuty; if (oEmployeeOutsideDuty != null) return oEmployeeOutsideDuty; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EmployeeOutsideDutyDA.Get(tc, id)); if (oreader.Read()) { oEmployeeOutsideDuty = 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(oEmployeeOutsideDuty, "Get", id); #endregion return oEmployeeOutsideDuty; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate employeeOutsideDutys = _cache["Get"] as ObjectsTemplate; if (employeeOutsideDutys != null) return employeeOutsideDutys; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmployeeOutsideDutyDA.Get(tc)); employeeOutsideDutys = 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(employeeOutsideDutys, "Get"); #endregion return employeeOutsideDutys; } public ObjectsTemplate GetByEmpID(ID empID) { #region Cache Header ObjectsTemplate employeeOutsideDutys = _cache["Get", empID] as ObjectsTemplate; if (employeeOutsideDutys != null) return employeeOutsideDutys; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmployeeOutsideDutyDA.GetByEmpID(tc, empID)); employeeOutsideDutys = 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(employeeOutsideDutys, "Get", empID); #endregion return employeeOutsideDutys; } public ObjectsTemplate Get(DateTime attnDate) { #region Cache Header ObjectsTemplate employeeOutsideDutys = _cache["Get", attnDate] as ObjectsTemplate; if (employeeOutsideDutys != null) return employeeOutsideDutys; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmployeeOutsideDutyDA.Get(tc, attnDate)); employeeOutsideDutys = 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(employeeOutsideDutys, "Get", attnDate); #endregion return employeeOutsideDutys; } public ID Save(EmployeeOutsideDuty oEmployeeOutsideDuty) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oEmployeeOutsideDuty.IsNew) { int id = tc.GenerateID("EmployeeOutsideDuty", "EmployeeOutsideDutyID"); base.SetObjectID(oEmployeeOutsideDuty, ID.FromInteger(id)); EmployeeOutsideDutyDA.Insert(tc, oEmployeeOutsideDuty); } else { EmployeeOutsideDutyDA.Update(tc, oEmployeeOutsideDuty); } tc.End(); return oEmployeeOutsideDuty.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 id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); EmployeeOutsideDutyDA.Delete(tc, id); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public bool IsOutsideDutyAvailable(DateTime startDate, DateTime endDate, ID empID) { bool isExist = false; TransactionContext tc = null; try { tc = TransactionContext.Begin(); isExist = EmployeeOutsideDutyDA.IsOutsideDutyAvailable(tc, startDate, endDate, empID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return isExist; } #endregion } #endregion }