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; using System.Data; namespace Payroll.Service.Attendence.Service { #region ShiftTerm Service [Serializable] public class ShiftTermService : ServiceTemplate, IShiftTermService { #region Private functions and declaration Cache _cache = new Cache(typeof(ShiftTerm)); #endregion public ShiftTermService() { } private void MapObject(ShiftTerm oShiftTerm, DataReader oReader) { base.SetObjectID(oShiftTerm, oReader.GetID("ShiftTermID")); oShiftTerm.ShiftID = oReader.GetID("ShiftID"); oShiftTerm.WeekendTermID = oReader.GetID("WeekendTermID"); oShiftTerm.HolidayTermID = oReader.GetID("HolidayTermID"); oShiftTerm.CreatedBy = oReader.GetID("CreatedBy"); oShiftTerm.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oShiftTerm.ModifiedBy = oReader.GetID("ModifiedBy"); oShiftTerm.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oShiftTerm, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ShiftTerm oShiftTerm = new ShiftTerm(); MapObject(oShiftTerm, oReader); return oShiftTerm as T; } protected ShiftTerm CreateObject(DataReader oReader) { ShiftTerm oShiftTerm = new ShiftTerm(); MapObject(oShiftTerm, oReader); return oShiftTerm; } #region Service implementation public ShiftTerm Get(ID id) { ShiftTerm oShiftTerm = new ShiftTerm(); #region Cache Header oShiftTerm = _cache["Get", id] as ShiftTerm; if (oShiftTerm != null) return oShiftTerm; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ShiftTermDA.Get(tc, id)); if (oreader.Read()) { oShiftTerm = 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(oShiftTerm, "Get", id); #endregion return oShiftTerm; } public ShiftTerm GetByShiftID(ID shiftID) { ShiftTerm oShiftTerm = new ShiftTerm(); #region Cache Header oShiftTerm = _cache["GetByShiftID", shiftID] as ShiftTerm; if (oShiftTerm != null) return oShiftTerm; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ShiftTermDA.GetByShiftID(tc, shiftID)); if (oreader.Read()) { oShiftTerm = 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(oShiftTerm, "GetByShiftID", shiftID); #endregion return oShiftTerm; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate shiftTerms = _cache["Get"] as ObjectsTemplate; if (shiftTerms != null) return shiftTerms; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ShiftTermDA.Get(tc)); shiftTerms = 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(shiftTerms, "Get"); #endregion return shiftTerms; } public ID Save(ShiftTerm oShiftTerm) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oShiftTerm.IsNew) { int id = tc.GenerateID("ShiftTerm", "ShiftTermID"); base.SetObjectID(oShiftTerm, ID.FromInteger(id)); ShiftTermDA.Insert(tc, oShiftTerm); } else { ShiftTermDA.Update(tc, oShiftTerm); } tc.End(); return oShiftTerm.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); ShiftTermDA.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 DataSet GetEmpOT(DateTime date, ID termID) { DataSet empOT = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); empOT = ShiftTermDA.GetEmpOT(tc, date, termID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return empOT; } #endregion } #endregion }