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

272 lines
7.2 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 Claim Balance Service
public class ClaimBalanceService : ServiceTemplate, IClaimBalaceService
{
public ClaimBalanceService()
{
}
#region MapObject For Asset
private void MapObject(ClaimBalance oClaimBalance, DataReader oReader)
{
base.SetObjectID(oClaimBalance, oReader.GetInt32("ClaimBalanceID").Value);
oClaimBalance.EmployeeID = oReader.GetInt32("EmployeeID").Value;
oClaimBalance.Balance = oReader.GetDouble("Balance", 0);
this.SetObjectState(oClaimBalance, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ClaimBalance oClaimBalance = new ClaimBalance();
MapObject(oClaimBalance, oReader);
return oClaimBalance as T;
}
#endregion
#region Service Implemantation
public ClaimBalance Get(int id)
{
ClaimBalance oClaimBalance = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ClaimBalanceDA.Get(tc, id));
if (oreader.Read())
{
oClaimBalance = this.CreateObject<ClaimBalance>(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 oClaimBalance;
}
public ClaimBalance GetByEmployeeId(int employeeId,TransactionContext tc)
{
ClaimBalance oClaimBalance = null;
try
{
// tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ClaimBalanceDA.GetByEmployeeId(tc, employeeId));
if (oreader.Read())
{
oClaimBalance = this.CreateObject<ClaimBalance>(oreader);
}
oreader.Close();
}
catch (Exception e)
{
#region Handle Exception
throw new ServiceException(e.Message, e);
#endregion
}
return oClaimBalance;
}
public List<ClaimBalance> Get()
{
List<ClaimBalance> ClaimBalanceList = new List<ClaimBalance>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ClaimBalanceDA.Get(tc));
ClaimBalanceList = this.CreateObjects<ClaimBalance>(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 ClaimBalanceList;
}
public ClaimCurrentBalance GetCurrentBalancebyEmployeeId(int employeeId)
{
ClaimCurrentBalance claimCurrentbalance = null ;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ClaimBalanceDA.GetCurrentBalancebyEmployeeId(tc, employeeId));
while (dr.Read())
{
claimCurrentbalance = new ClaimCurrentBalance();
claimCurrentbalance.CurrentBalance = dr.GetDouble("CurrentBalance", 0);
claimCurrentbalance.AdavnceAmount = dr.GetDouble("AdvanceAmount",0);
claimCurrentbalance.ExpenseAmount = dr.GetDouble("ExpenseAmount",0);
}
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 claimCurrentbalance;
}
public int Save(ClaimBalance oClaimBalance)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oClaimBalance.IsNew)
{
int id = tc.GenerateID("ClaimBalance", "ClaimBalanceID");
base.SetObjectID(oClaimBalance, (id));
ClaimBalanceDA.Insert(tc, oClaimBalance);
}
else
{
ClaimBalanceDA.Update(tc, oClaimBalance);
}
return oClaimBalance.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(ClaimBalance oClaimBalance, TransactionContext tc)
{
try
{
if (oClaimBalance.IsNew)
{
int id = tc.GenerateID("ClaimBalance", "ClaimBalanceID");
base.SetObjectID(oClaimBalance, (id));
ClaimBalanceDA.Insert(tc, oClaimBalance);
}
else
{
ClaimBalanceDA.Update(tc, oClaimBalance);
}
return oClaimBalance.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);
ClaimBalanceDA.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
}