EchoTex_Payroll/HRM.DA/Service/OverTime/OTSlabService.cs
2024-10-14 10:01:49 +06:00

231 lines
5.9 KiB
C#

using HRM.BO;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
namespace HRM.DA
{
#region OTSlab Service
public class OTSlabService : ServiceTemplate
{
#region Private functions and declaration
#endregion
public OTSlabService()
{
}
private void MapObject(OTSlab oOTSlab, DataReader oReader)
{
base.SetObjectID(oOTSlab, oReader.GetInt32("OTSlabID").Value);
oOTSlab.Hours = oReader.GetInt32("hours").Value;
oOTSlab.Amount = oReader.GetInt32("amount").Value;
oOTSlab.TermID = oReader.GetString("TermID") == null ? 0 : oReader.GetInt32("TermID").Value;
this.SetObjectState(oOTSlab, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
OTSlab oOTSlab = new OTSlab();
MapObject(oOTSlab, oReader);
return oOTSlab as T;
}
protected OTSlab CreateObject(DataReader oReader)
{
OTSlab oOTSlab = new OTSlab();
MapObject(oOTSlab, oReader);
return oOTSlab;
}
#region Service implementation
public OTSlab Get(int id)
{
OTSlab oOTSlab = new OTSlab();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OTSlabDA.Get(tc, id));
if (oreader.Read())
{
oOTSlab = this.CreateObject<OTSlab>(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 oOTSlab;
}
public List<OTSlab> Get()
{
List<OTSlab> oTSlabs = new List<OTSlab>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OTSlabDA.Get(tc));
oTSlabs = this.CreateObjects<OTSlab>(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
}
return oTSlabs;
}
public List<OTSlab> GetByTermID(int nTermID)
{
List<OTSlab> oTSlabs = new List<OTSlab>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OTSlabDA.GetByTermID(tc, nTermID));
oTSlabs = this.CreateObjects<OTSlab>(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
}
return oTSlabs;
}
public int Save(OTSlab oOTSlab)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oOTSlab.IsNew)
{
int id = tc.GenerateID("OTSlab", "OTSlabID");
base.SetObjectID(oOTSlab, id);
OTSlabDA.Insert(tc, oOTSlab);
}
else
{
OTSlabDA.Update(tc, oOTSlab);
}
tc.End();
return oOTSlab.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<OTSlab> _OTSlabs)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
OTSlabDA.DeleteByTermID(tc, _OTSlabs[0].TermID);
foreach (OTSlab oTSlab in _OTSlabs)
{
if (oTSlab.IsNew)
{
int id = tc.GenerateID("OTSlab", "OTSlabID");
base.SetObjectID(oTSlab, id);
OTSlabDA.Insert(tc, oTSlab);
}
}
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);
OTSlabDA.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
}