CEL_Payroll/Payroll.Service/Attendence/Service/AutoWorkPalnService.cs

167 lines
5.5 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.Caching;
using Payroll.BO;
using Ease.CoreV35.DataAccess;
using Ease.CoreV35.Model;
using Payroll.Service.Attendence.DA;
namespace Payroll.Service.Attendence.Service
{
#region AutoWorkPlan Service
[Serializable]
public class AutoWorkPlanService : ServiceTemplate, IAutoWorkPlanService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(AutoWorkPlan));
#endregion
public AutoWorkPlanService() { }
private void MapObject(AutoWorkPlan oAutoWorkPlan, DataReader oReader)
{
base.SetObjectID(oAutoWorkPlan, oReader.GetID("AutoWorkPlanID"));
oAutoWorkPlan.EmployeeID = oReader.GetID("EmployeeID");
oAutoWorkPlan.ShiftID = oReader.GetID("ShiftID");
oAutoWorkPlan.StartDate = oReader.GetDateTime("StartDate").Value;
oAutoWorkPlan.CreatedBy = oReader.GetID("CreatedBy");
oAutoWorkPlan.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oAutoWorkPlan.ModifiedBy = oReader.GetID("ModifiedBy");
oAutoWorkPlan.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oAutoWorkPlan, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
AutoWorkPlan oAutoWorkPlan = new AutoWorkPlan();
MapObject(oAutoWorkPlan, oReader);
return oAutoWorkPlan as T;
}
protected AutoWorkPlan CreateObject(DataReader oReader)
{
AutoWorkPlan oAutoWorkPlan = new AutoWorkPlan();
MapObject(oAutoWorkPlan, oReader);
return oAutoWorkPlan;
}
#region Service implementation
public AutoWorkPlan Get(ID id)
{
AutoWorkPlan oAutoWorkPlan = new AutoWorkPlan();
#region Cache Header
oAutoWorkPlan = _cache["Get", id] as AutoWorkPlan;
if (oAutoWorkPlan != null)
return oAutoWorkPlan;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(AutoWorkPlanDA.Get(tc, id));
if (oreader.Read())
{
oAutoWorkPlan = this.CreateObject<AutoWorkPlan>(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(oAutoWorkPlan, "Get", id);
#endregion
return oAutoWorkPlan;
}
public ObjectsTemplate<AutoWorkPlan> Get()
{
#region Cache Header
ObjectsTemplate<AutoWorkPlan> autoWorkPlans = _cache["Get"] as ObjectsTemplate<AutoWorkPlan>;
if (autoWorkPlans != null)
return autoWorkPlans;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AutoWorkPlanDA.Get(tc));
autoWorkPlans = this.CreateObjects<AutoWorkPlan>(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(autoWorkPlans, "Get");
#endregion
return autoWorkPlans;
}
public ID Save(AutoWorkPlan oAutoWorkPlan)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oAutoWorkPlan.IsNew)
{
int id = tc.GenerateID("AutoWorkPlan", "AutoWorkPlanID");
base.SetObjectID(oAutoWorkPlan, ID.FromInteger(id));
AutoWorkPlanDA.Insert(tc, oAutoWorkPlan);
}
else
{
AutoWorkPlanDA.Update(tc, oAutoWorkPlan);
}
tc.End();
return oAutoWorkPlan.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);
AutoWorkPlanDA.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
}