209 lines
5.6 KiB
C#
209 lines
5.6 KiB
C#
using Ease.Core.DataAccess;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.Utility;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using HRM.BO;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
public class LoanTransactionService : ServiceTemplate //, ILoanTransactionService
|
|
{
|
|
public LoanTransactionService()
|
|
{
|
|
}
|
|
|
|
private void MapObject(FMLoanTransaction loanTran, DataReader dr)
|
|
{
|
|
base.SetObjectID(loanTran, dr.GetInt32("LoanTransactionID").Value);
|
|
|
|
loanTran.CustomerID = dr.GetInt32("CustomerID").Value;
|
|
loanTran.LoanID = dr.GetInt32("LoanID").Value;
|
|
loanTran.LoanScheduleID = dr.GetInt32("LoanScheduleID").Value;
|
|
loanTran.Amount = dr.GetDouble("Amount").Value;
|
|
loanTran.PaymentDate = dr.GetDateTime("PaymentDate").Value;
|
|
loanTran.TranType = (EnumFMLoanTransactionType)dr.GetInt16("TranType").Value;
|
|
loanTran.CreatedBy = dr.GetInt32("CreatedBy").Value;
|
|
loanTran.CreatedDate = dr.GetDateTime("CreatedDate").Value;
|
|
loanTran.ModifiedBy = dr.GetInt32("ModifiedBy");
|
|
loanTran.ModifiedDate = dr.GetDateTime("ModifiedDate");
|
|
loanTran.FundTypeID = dr.GetInt32("FundTypeID").Value;
|
|
base.SetObjectState(loanTran, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader dr)
|
|
{
|
|
FMLoanTransaction loanTransaction = new FMLoanTransaction();
|
|
|
|
MapObject(loanTransaction, dr);
|
|
|
|
return loanTransaction as T;
|
|
}
|
|
|
|
protected FMLoanTransaction CreateObject(DataReader oReader)
|
|
{
|
|
FMLoanTransaction loanTransaction = new FMLoanTransaction();
|
|
MapObject(loanTransaction, oReader);
|
|
return loanTransaction;
|
|
}
|
|
|
|
#region Service Implementation
|
|
|
|
#region Insert
|
|
|
|
public void Save(FMLoanTransaction loanTransaction)
|
|
{
|
|
FMLoanTransaction oLoanTransaction = new FMLoanTransaction();
|
|
oLoanTransaction = loanTransaction;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oLoanTransaction.IsNew)
|
|
{
|
|
int id = tc.GenerateID("FM_LoanTransaction", "LoanTransactionID");
|
|
base.SetObjectID(oLoanTransaction, id);
|
|
LoanTransactionDA.Insert(tc, oLoanTransaction);
|
|
}
|
|
else
|
|
{
|
|
LoanTransactionDA.Update(tc, oLoanTransaction);
|
|
}
|
|
|
|
tc.End();
|
|
//return oLoanTransaction.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Delete
|
|
|
|
public void Delete(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
LoanTransactionDA.Delete(tc, id);
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException("Failed to Delete " + e.Message);
|
|
;
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Get(By LoanTransactionID)
|
|
|
|
public FMLoanTransaction Get(int loanTransactionID)
|
|
{
|
|
FMLoanTransaction loanTransaction = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(LoanTransactionDA.Get(tc, loanTransactionID));
|
|
if (dr.Read())
|
|
{
|
|
loanTransaction = this.CreateObject<FMLoanTransaction>(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 loanTransaction;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Get()
|
|
|
|
public List<FMLoanTransaction> Get()
|
|
{
|
|
List<FMLoanTransaction> loanTransactions = new List<FMLoanTransaction>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(LoanTransactionDA.Get(tc));
|
|
loanTransactions = this.CreateObjects<FMLoanTransaction>(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 loanTransactions;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetTable
|
|
|
|
public DataTable GetTable()
|
|
{
|
|
DataTable dTbl = new DataTable("LoanTransaction");
|
|
return dTbl;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
} |