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

192 lines
5.4 KiB
C#
Raw Permalink 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 DailyOTProcess Service
[Serializable]
public class DailyOTProcessService : ServiceTemplate
{
public DailyOTProcessService()
{
}
private void MapObject(DailyOTProcess oDailyOTProcess, DataReader oReader)
{
base.SetObjectID(oDailyOTProcess, (oReader.GetInt32("ProcessID").Value));
oDailyOTProcess.TermID = oReader.GetInt32("termID", 0);
oDailyOTProcess.Value = oReader.GetInt32("value").Value;
oDailyOTProcess.EmployeeID = oReader.GetInt32("employeeID", 0);
oDailyOTProcess.WorkingDate = oReader.GetDateTime("workingdate").Value;
this.SetObjectState(oDailyOTProcess, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
DailyOTProcess oDailyOTProcess = new DailyOTProcess();
MapObject(oDailyOTProcess, oReader);
return oDailyOTProcess as T;
}
#region Service implementation
public DailyOTProcess Get(int id)
{
DailyOTProcess oDailyOTProcess = new DailyOTProcess();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DailyOTProcessDA.Get(tc, id));
if (oreader.Read())
{
oDailyOTProcess = this.CreateObject<DailyOTProcess>(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 oDailyOTProcess;
}
public List<DailyOTProcess> Get()
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DailyOTProcessDA.Get(tc));
var dailyOTProcesses = this.CreateObjects<DailyOTProcess>(dr);
dr.Close();
tc.End();
return dailyOTProcesses;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(DailyOTProcess oDailyOTProcess)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oDailyOTProcess.IsNew)
{
int id = tc.GenerateID("DailyOTProcess", "ProcessID");
base.SetObjectID(oDailyOTProcess, (id));
DailyOTProcessDA.Insert(tc, oDailyOTProcess);
}
else
{
DailyOTProcessDA.Update(tc, oDailyOTProcess);
}
tc.End();
return oDailyOTProcess.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Save(List<DailyOTProcess> oDailyOTProcesses)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (DailyOTProcess oDailyOTProcess in oDailyOTProcesses)
{
if (oDailyOTProcess.IsNew)
{
int id = tc.GenerateID("DailyOTProcess", "ProcessID");
base.SetObjectID(oDailyOTProcess, (id));
DailyOTProcessDA.Insert(tc, oDailyOTProcess);
}
else
{
DailyOTProcessDA.Update(tc, oDailyOTProcess);
}
tc.End();
}
}
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);
DailyOTProcessDA.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
}