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(LoanTransaction 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 = (EnumLoanTransactionType)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.ProjectID = dr.GetInt32("ProjectID").Value; base.SetObjectState(loanTran, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader dr) { LoanTransaction loanTransaction = new LoanTransaction(); MapObject(loanTransaction, dr); return loanTransaction as T; } protected LoanTransaction CreateObject(DataReader oReader) { LoanTransaction loanTransaction = new LoanTransaction(); MapObject(loanTransaction, oReader); return loanTransaction; } #region Service Implementation #region Insert public void Save(LoanTransaction loanTransaction) { LoanTransaction oLoanTransaction = new LoanTransaction(); oLoanTransaction = loanTransaction; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oLoanTransaction.IsNew) { int id = tc.GenerateID("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 LoanTransaction Get(int loanTransactionID) { LoanTransaction loanTransaction = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LoanTransactionDA.Get(tc, loanTransactionID)); if (dr.Read()) { loanTransaction = this.CreateObject(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 Get() { List loanTransactions = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LoanTransactionDA.Get(tc)); loanTransactions = this.CreateObjects(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 } }