EchoTex_Payroll/HRM.DA/Service/Claim/ClaimTranService.cs

232 lines
6.1 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core.Utility;
using System.Collections.Generic;
using HRM.BO;
using HRM.BO.Configuration;
using Microsoft.Extensions.Configuration;
using System.Threading;
using System.IO;
using HRM.DA.DA.Assets;
namespace HRM.DA
{
#region Asset Service
public class ClaimTranService : ServiceTemplate, IClaimTranService
{
public ClaimTranService()
{
}
#region MapObject For Asset
private void MapObject(ClaimTran oClaimtran, DataReader oReader)
{
base.SetObjectID(oClaimtran, oReader.GetInt32("ClaimTranID").Value);
oClaimtran.EmployeeID = oReader.GetInt32("EmployeeID").Value;
oClaimtran.TranDate = oReader.GetDateTime("TranDate").Value;
oClaimtran.TranType = (EnumTranType)oReader.GetInt32("TranType").Value;
oClaimtran.ReferenceID = oReader.GetInt32("ReferenceID").Value;
oClaimtran.Remarks = oReader.GetString("Remarks", null);
oClaimtran.TranSide = (EnumSide)oReader.GetInt32("TranSide");
oClaimtran.TranAmount = oReader.GetDouble("TranAmount", 0);
this.SetObjectState(oClaimtran, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ClaimTran oClaimtran = new ClaimTran();
MapObject(oClaimtran, oReader);
return oClaimtran as T;
}
#endregion
#region Service Implemantation
public ClaimTran Get(int id)
{
ClaimTran oAsset = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ClaimTranDA.Get(tc, id));
if (oreader.Read())
{
oAsset = this.CreateObject<ClaimTran>(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 oAsset;
}
public List<ClaimTran> Get()
{
List<ClaimTran> AssetSerials = new List<ClaimTran>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ClaimTranDA.Get(tc));
AssetSerials = this.CreateObjects<ClaimTran>(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 AssetSerials;
}
public List<ClaimTran> GetByEmployeeId(int employeeId, TransactionContext tc)
{
List<ClaimTran> oClaimBalance = new List<ClaimTran>();
try
{
DataReader oreader = new DataReader(ClaimTranDA.GetByEmployeeId(tc, employeeId));
oClaimBalance = this.CreateObjects<ClaimTran>(oreader);
oreader.Close();
}
catch (Exception e)
{
#region Handle Exception
throw new ServiceException(e.Message, e);
#endregion
}
return oClaimBalance;
}
public int Save(ClaimTran oClaimTran)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oClaimTran.IsNew)
{
int id = tc.GenerateID("ClaimTran", "ClaimTranID");
base.SetObjectID(oClaimTran, (id));
ClaimTranDA.Insert(tc, oClaimTran);
}
else
{
ClaimTranDA.Update(tc, oClaimTran);
}
return oClaimTran.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
tc.End();
}
}
public int Save(ClaimTran oClaimTran, TransactionContext tc)
{
try
{
if (oClaimTran.IsNew)
{
int id = tc.GenerateID("ClaimTran", "ClaimTranID");
base.SetObjectID(oClaimTran, (id));
ClaimTranDA.Insert(tc, oClaimTran);
}
else
{
ClaimTranDA.Update(tc, oClaimTran);
}
return oClaimTran.ID;
}
catch (Exception e)
{
#region Handle Exception
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ClaimTranDA.Delete(tc, id);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
finally
{
tc.End();
}
}
#endregion
}
#endregion
}