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.BO; using Payroll.Service.Attendence.DA; namespace Payroll.Service.Attendence.Service { #region WorkPlanGroup Service [Serializable] public class WorkPlanGroupService : ServiceTemplate, IWorkPlanGroupService { #region Private functions and declaration Cache _cache = new Cache(typeof(WorkPlanGroup)); #endregion public WorkPlanGroupService() { } private void MapObject(WorkPlanGroup oWorkPlanGroup, DataReader oReader) { base.SetObjectID(oWorkPlanGroup, oReader.GetID("WorkPlanGroupID")); oWorkPlanGroup.Name = oReader.GetString("Name"); oWorkPlanGroup.FromTime = oReader.GetDateTime("FromTime").HasValue ? oReader.GetDateTime("FromTime").Value : DateTime.MinValue; oWorkPlanGroup.ToTime = oReader.GetDateTime("ToTime").HasValue ? oReader.GetDateTime("ToTime").Value : DateTime.MinValue; //oWorkPlanGroup.FromTime = oReader.GetDateTime("FromTime").Value; //oWorkPlanGroup.ToTime = oReader.GetDateTime("ToTime").Value; oWorkPlanGroup.Type = (EnumWorkPlanGroup)oReader.GetInt32("Type").Value; oWorkPlanGroup.Sequence = oReader.GetInt32("SequenceNo").Value; oWorkPlanGroup.Status = (EnumStatus)oReader.GetInt32("Status").Value; oWorkPlanGroup.CreatedBy = oReader.GetID("CreatedBy"); oWorkPlanGroup.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oWorkPlanGroup.ModifiedBy = oReader.GetID("ModifiedBy"); oWorkPlanGroup.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oWorkPlanGroup.PayrollTypeID = oReader.GetID("PayrollTypeID"); this.SetObjectState(oWorkPlanGroup, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { WorkPlanGroup oWorkPlanGroup = new WorkPlanGroup(); MapObject(oWorkPlanGroup, oReader); return oWorkPlanGroup as T; } protected WorkPlanGroup CreateObject(DataReader oReader) { WorkPlanGroup oWorkPlanGroup = new WorkPlanGroup(); MapObject(oWorkPlanGroup, oReader); return oWorkPlanGroup; } #region Service implementation public WorkPlanGroup GetByID(ID id,ID PayrollTypeID) { WorkPlanGroup oWorkPlanGroup = new WorkPlanGroup(); #region Cache Header oWorkPlanGroup = _cache["Get", id] as WorkPlanGroup; if (oWorkPlanGroup != null) return oWorkPlanGroup; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(WorkPlanGroupDA.Get(tc, id, PayrollTypeID)); if (oreader.Read()) { oWorkPlanGroup = 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(oWorkPlanGroup, "Get", id); #endregion return oWorkPlanGroup; } public ObjectsTemplate Get(ID PayrolltypeID) { #region Cache Header ObjectsTemplate workPlanGroups = _cache["Get"] as ObjectsTemplate; if (workPlanGroups != null) return workPlanGroups; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WorkPlanGroupDA.Get(tc, PayrolltypeID)); workPlanGroups = 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(workPlanGroups, "Get"); #endregion return workPlanGroups; } public ObjectsTemplate Get(EnumStatus status, ID PayrolltypeID) { #region Cache Header ObjectsTemplate workPlanGroups = _cache["Get", status] as ObjectsTemplate; if (workPlanGroups != null) return workPlanGroups; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WorkPlanGroupDA.Get(tc, status, PayrolltypeID)); workPlanGroups = 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(workPlanGroups, "Get", status); #endregion return workPlanGroups; } public ObjectsTemplate Get(EnumWorkPlanGroup wpg, ID PayrolltypeID) { #region Cache Header ObjectsTemplate workPlanGroups = _cache["Get", wpg] as ObjectsTemplate; if (workPlanGroups != null) return workPlanGroups; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WorkPlanGroupDA.Get(tc, wpg, PayrolltypeID)); workPlanGroups = 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(workPlanGroups, "Get", wpg); #endregion return workPlanGroups; } public ID Save(WorkPlanGroup oWorkPlanGroup, ID PayrolltypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oWorkPlanGroup.IsNew) { int id = tc.GenerateID("WorkPlanGroup", "WorkPlanGroupID"); base.SetObjectID(oWorkPlanGroup, ID.FromInteger(id)); int seqNo = tc.GenerateID("WorkPlanGroup", "SequenceNO"); oWorkPlanGroup.Sequence = seqNo; WorkPlanGroupDA.Insert(tc, oWorkPlanGroup, PayrolltypeID); } else { WorkPlanGroupDA.Update(tc, oWorkPlanGroup, PayrolltypeID); } tc.End(); return oWorkPlanGroup.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); WorkPlanGroupDA.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 } } #endregion } #endregion }