EchoTex_Payroll/HRM.DA/Service/PMP/PMSExceptionService.cs

174 lines
5.0 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Ease.Core.Utility;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using HRM.BO;
namespace HRM.DA
{
#region PMSException Service
public class PMSExceptionService : ServiceTemplate
{
public PMSExceptionService()
{
}
private void MapObject(PMSException oPMSException, DataReader oReader)
{
base.SetObjectID(oPMSException, oReader.GetInt32("PMSExceptionID").Value);
oPMSException.PMPYearID = oReader.GetInt32("PMPYearID").Value;
oPMSException.EmployeeID = oReader.GetInt32("EmployeeID").Value;
oPMSException.TireID = oReader.GetInt32("TierID").Value;
oPMSException.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oPMSException.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oPMSException.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oPMSException.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oPMSException, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
PMSException oPMSException = new PMSException();
MapObject(oPMSException, oReader);
return oPMSException as T;
}
protected PMSException CreateObject(DataReader oReader)
{
PMSException oPMSException = new PMSException();
MapObject(oPMSException, oReader);
return oPMSException;
}
#region Service implementation
public PMSException Get(int nPMPYearID, int nEmpID)
{
PMSException oPMSException = new PMSException();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PMSExceptionDA.Get(tc, nPMPYearID, nEmpID));
if (oreader.Read())
{
oPMSException = this.CreateObject<PMSException>(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 oPMSException;
}
public List<PMSException> Get(int nPMPYearID)
{
List<PMSException> oPMSExceptions = new List<PMSException>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PMSExceptionDA.Get(tc, nPMPYearID));
oPMSExceptions = this.CreateObjects<PMSException>(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 oPMSExceptions;
}
public void Save(List<PMSException> oPMSExceptions)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (PMSException oPMSException in oPMSExceptions)
{
if (oPMSException.IsNew)
{
int id = tc.GenerateID("PMSException", "PMSExceptionID");
base.SetObjectID(oPMSException, id);
PMSExceptionDA.Insert(tc, oPMSException);
}
else
{
PMSExceptionDA.Update(tc, oPMSException);
}
}
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);
PMSExceptionDA.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
}