EchoTex_Payroll/HRM.DA/Service/Attendance/AutoWorkPalnService.cs

159 lines
4.5 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
#region AutoWorkPlan Service
[Serializable]
public class AutoWorkPlanService : ServiceTemplate
{
public AutoWorkPlanService()
{
}
private void MapObject(AutoWorkPlan oAutoWorkPlan, DataReader oReader)
{
base.SetObjectID(oAutoWorkPlan, (oReader.GetInt32("AutoWorkPlanID").Value));
oAutoWorkPlan.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oAutoWorkPlan.ShiftID = oReader.GetInt32("ShiftID", 0);
oAutoWorkPlan.StartDate = oReader.GetDateTime("StartDate").Value;
oAutoWorkPlan.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oAutoWorkPlan.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oAutoWorkPlan.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oAutoWorkPlan.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oAutoWorkPlan, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
AutoWorkPlan oAutoWorkPlan = new AutoWorkPlan();
MapObject(oAutoWorkPlan, oReader);
return oAutoWorkPlan as T;
}
#region Service implementation
public AutoWorkPlan Get(int id)
{
AutoWorkPlan oAutoWorkPlan = new AutoWorkPlan();
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
}
return oAutoWorkPlan;
}
public List<AutoWorkPlan> Get()
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AutoWorkPlanDA.Get(tc));
var autoWorkPlans = this.CreateObjects<AutoWorkPlan>(dr);
dr.Close();
tc.End();
return autoWorkPlans;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(AutoWorkPlan oAutoWorkPlan)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oAutoWorkPlan.IsNew)
{
int id = tc.GenerateID("AutoWorkPlan", "AutoWorkPlanID");
base.SetObjectID(oAutoWorkPlan, (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(int 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
}