EchoTex_Payroll/HRM.DA/Service/FundEss/LoanApplicationService.cs

281 lines
10 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using HRM.BO;
using Payroll.BO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static iTextSharp.text.pdf.AcroFields;
namespace HRM.DA
{
public class LoanApplicationService : ServiceTemplate,ILoanApplicationService
{
#region Map Object
private void MapObject(LoanApplication oLoanApplication, DataReader oReader)
{
SetObjectID(oLoanApplication, oReader.GetInt32("LoanAppID").Value);
oLoanApplication.LoanAppID = oReader.GetInt32("LoanAppID").Value;
oLoanApplication.LoanAppNO = oReader.GetInt32("LoanAppNO").Value;
oLoanApplication.ApplyDate = oReader.GetDateTime("ApplyDate").Value;
oLoanApplication.MemberID = oReader.GetInt32("MemberID").Value;
oLoanApplication.EmployeeID = oReader.GetInt32("EmployeeID").Value;
oLoanApplication.LoanAmount = oReader.GetDecimal("LoanAmount").Value;
oLoanApplication.NoOfInstallment = oReader.GetInt32("NoOfInstallment").Value;
oLoanApplication.InstallmentAmount = oReader.GetDecimal("InstallmentAmount").Value;
oLoanApplication.Principal = oReader.GetDecimal("Principal").Value;
oLoanApplication.Interest = oReader.GetDecimal("Interest").Value;
oLoanApplication.purposeID = (enumLoanPurpose)oReader.GetInt32("purposeID").Value;
oLoanApplication.Remarks = oReader.GetString("Remarks");
oLoanApplication.FundJoining = oReader.GetDateTime("FundJoining").Value;
oLoanApplication.BasicSalary = oReader.GetDecimal("BasicSalary").Value;
oLoanApplication.GrossSalary = oReader.GetDecimal("GrossSalary").Value;
oLoanApplication.PreviouslyTakenLoan = oReader.GetBoolean("PreviouslyTakenLoan").GetValueOrDefault();
oLoanApplication.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oLoanApplication.CreatedBy = oReader.GetInt32("CreatedBy").Value;
oLoanApplication.AccountUserID = oReader.GetInt32("AccountUserID");
oLoanApplication.AccountAppDate = oReader.GetDateTime("AccountAppDate");
oLoanApplication.AccountsRemarks = oReader.GetString("AccountsRemarks");
oLoanApplication.HRUserID = oReader.GetInt32("HRUserID");
oLoanApplication.HRApproveDate = oReader.GetDateTime("HRApproveDate");
oLoanApplication.HRApproveRemarks = oReader.GetString("HRApproveRemarks");
oLoanApplication.TrusteesID = oReader.GetInt32("TrusteesID");
oLoanApplication.TrusteesApproveDate = oReader.GetDateTime("TrusteesApproveDate");
oLoanApplication.TrusteesApproveRemarks = oReader.GetString("TrusteesApproveRemarks");
// Set the object state
SetObjectState(oLoanApplication, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
LoanApplication oLoanApplication = new LoanApplication();
MapObject(oLoanApplication, oReader);
return oLoanApplication as T;
}
#endregion
#region Child Object Mapping
private List<LoanAttachment> CreateLoanAttachments(DataReader oReader)
{
List<LoanAttachment> oLoanAttachments = new List<LoanAttachment>();
while (oReader.Read())
{
LoanAttachment oLoanAttachment = new LoanAttachment();
MapLoanAttachmentObject(oLoanAttachment, oReader);
oLoanAttachments.Add(oLoanAttachment);
}
return oLoanAttachments;
}
private void MapLoanAttachmentObject(LoanAttachment oLoanAttachment, DataReader oReader)
{
SetObjectID(oLoanAttachment, oReader.GetInt32("LoanAttachmentID").Value);
oLoanAttachment.LoanAppID = oReader.GetInt32("LoanAppID").Value;
oLoanAttachment.LoanDocType = (enumLoanDocType)oReader.GetInt32("LoanDocType").Value;
oLoanAttachment.FileName = oReader.GetString("FileName");
oLoanAttachment.FileData = oReader.GetLob("FileData");
oLoanAttachment.FileDataString = oReader.GetString("FileDataString");
oLoanAttachment.uploadDate = oReader.GetDateTime("uploadDate").Value;
oLoanAttachment.uploadBy = oReader.GetInt32("uploadBy").Value;
SetObjectState(oLoanAttachment, Ease.Core.ObjectState.Saved);
}
#endregion
#region Get
public LoanApplication Get(int EmpId)
{
TransactionContext tc = null;
try
{
var oLoanApplication = new LoanApplication();
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(LoanApplicationDA.Get(tc, EmpId));
if (oreader.Read())
{
oLoanApplication = this.CreateObject<LoanApplication>(oreader);
}
oreader.Close();
tc.End();
return oLoanApplication;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public DataSet GetLoanApplicationData(int EmpID)
{
DataSet oGetLoanApplicationData = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oGetLoanApplicationData = LoanApplicationDA.GetLoanApplicationData(tc, EmpID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oGetLoanApplicationData;
}
#endregion
#region Get All
public List<LoanApplication> GetAll()
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanApplicationDA.GetAll(tc));
var oLoanApplication = this.CreateObjects<LoanApplication>(dr);
dr.Close();
tc.End();
return oLoanApplication;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
#region Save
public int Save(LoanApplication oLoanApplication)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oLoanApplication.IsNew)
{
int id = tc.GenerateID("LoanApplication", "LoanAppID");
base.SetObjectID(oLoanApplication, id);
LoanApplicationDA.Insert(tc, oLoanApplication);
}
else
{
LoanApplicationDA.Update(tc, oLoanApplication);
#region Delete Childs
LoanApplicationDA.DeleteLoanAttachments(tc, oLoanApplication.LoanAppID);
#endregion
}
#region Insert Childs
if (oLoanApplication.LoanAttachments != null && oLoanApplication.LoanAttachments.Count > 0)
{
foreach (LoanAttachment item in oLoanApplication.LoanAttachments)
{
if (item != null)
{
if (item.ID <= 0 && item.FileData != null)
{
item.LoanAppID = oLoanApplication.LoanAppID;
base.SetObjectID(item, tc.GenerateID("LoanAttachment", "LoanAttachmentID"));
LoanApplicationDA.InsertLoanAttachment(item, oLoanApplication.ConnectionString);
}
else
{
item.LoanAppID = oLoanApplication.LoanAppID;
item.FileData = null;
item.FileName = null;
base.SetObjectID(item, tc.GenerateID("LoanAttachment", "LoanAttachmentID"));
LoanApplicationDA.InsertLoanAttachment(item, oLoanApplication.ConnectionString);
}
}
}
}
#endregion
tc.End();
return oLoanApplication.LoanAppID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion Save
#region Delete
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
LoanApplicationDA.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
}
}