EchoTex_Payroll/HRM.DA/Service/Loan/LoanSettlementService.cs

183 lines
5.6 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using HRM.BO;
namespace HRM.DA
{
#region LoanSettlement Service
public class LoanSettlementService : ServiceTemplate
{
public LoanSettlementService()
{
}
#region MapObject For LoanSettlement
private void MapObject(LoanSettlement oLoanSettlement, DataReader oReader)
{
base.SetObjectID(oLoanSettlement, oReader.GetInt32("LoanSettlementID").Value);
oLoanSettlement.LoanIssueID =
oReader.GetString("LoanIssueID") == null ? 0 : oReader.GetInt32("LoanIssueID").Value;
oLoanSettlement.WFStatus = (EnumwfStatus)oReader.GetInt32("WFStatus").Value;
oLoanSettlement.BankID = oReader.GetString("BankID") == null ? 0 : oReader.GetInt32("BankID").Value;
oLoanSettlement.BranchID = oReader.GetString("BranchID") == null ? 0 : oReader.GetInt32("BranchID").Value;
oLoanSettlement.ChequeNo = oReader.GetString("ChequeNo");
oLoanSettlement.AccountNo = oReader.GetString("AccountNo");
oLoanSettlement.SubmitDate = oReader.GetDateTime("SubmitDate").Value;
oLoanSettlement.Remarks = oReader.GetString("Remarks");
oLoanSettlement.CreatedBy =
oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value;
oLoanSettlement.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oLoanSettlement.ModifiedBy =
oReader.GetString("ModifiedBy") == null ? 0 : oReader.GetInt32("ModifiedBy").Value;
oLoanSettlement.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oLoanSettlement, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
LoanSettlement oLoanSettlement = new LoanSettlement();
MapObject(oLoanSettlement, oReader);
return oLoanSettlement as T;
}
protected LoanSettlement CreateObject(DataReader oReader)
{
LoanSettlement oLoanSettlement = new LoanSettlement();
MapObject(oLoanSettlement, oReader);
return oLoanSettlement;
}
#endregion
#region Service Implementation of Loan Settlement
public LoanSettlement Get(int id)
{
LoanSettlement oLoanSettlement = new LoanSettlement();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(LoanSettlementDA.Get(tc, id));
if (oreader.Read())
{
oLoanSettlement = this.CreateObject<LoanSettlement>(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 oLoanSettlement;
}
public List<LoanSettlement> Get()
{
List<LoanSettlement> LoanSettlements = new List<LoanSettlement>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanSettlementDA.Get(tc));
LoanSettlements = this.CreateObjects<LoanSettlement>(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 LoanSettlements;
}
public int Save(LoanSettlement oLoanSettlement)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oLoanSettlement.IsNew)
{
int id = tc.GenerateID("LoanSettlement", "LoanSettlementID");
base.SetObjectID(oLoanSettlement, id);
LoanSettlementDA.Insert(tc, oLoanSettlement);
}
else
{
LoanSettlementDA.Update(tc, oLoanSettlement);
}
return oLoanSettlement.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 void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
LoanSettlementDA.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
}