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 LoanParameter Service public class LoanParameterService : ServiceTemplate, ILoanParameterService { public LoanParameterService() { } #region MapObject For LoanParameter private void MapObject(LoanParameter oLoanParameter, DataReader oReader) { base.SetObjectID(oLoanParameter, oReader.GetInt32("LoanParameterID").Value); oLoanParameter.LoanID = oReader.GetString("LoanID") == null ? 0 : oReader.GetInt32("LoanID").Value; oLoanParameter.NoOfGross = oReader.GetDouble("NoOfGross").Value; oLoanParameter.NoOfBasic = oReader.GetDouble("NoOfBasic").Value; oLoanParameter.MinInstallmentMonth = oReader.GetInt32("MinInstallmentMonth").Value; oLoanParameter.MaxInstallmentMonth = oReader.GetInt32("MaxInstallmentMonth").Value; oLoanParameter.MinReconcileMonth = oReader.GetInt32("MinReconcileMonth").Value; oLoanParameter.PayrollTypeID = oReader.GetString("PayrollTypeID") == null ? 0 : oReader.GetInt32("PayrollTypeID").Value; oLoanParameter.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value; oLoanParameter.CreatedDate = oReader.GetDateTime("CreationDate").Value; oLoanParameter.ModifiedBy = oReader.GetString("ModifiedBy") == null ? 0 : oReader.GetInt32("ModifiedBy").Value; oLoanParameter.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oLoanParameter.MinFlatAmount = oReader.GetDouble("MinFlatAmount").Value; oLoanParameter.MaxFlatAmount = oReader.GetDouble("MaxFlatAmount").Value; this.SetObjectState(oLoanParameter, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { LoanParameter oLoanParameter = new LoanParameter(); MapObject(oLoanParameter, oReader); return oLoanParameter as T; } protected LoanParameter CreateObject(DataReader oReader) { LoanParameter oLoanParameter = new LoanParameter(); MapObject(oLoanParameter, oReader); return oLoanParameter; } #endregion #region MapObject For LoanGrades private void MapLoanGrades(LoanGrades oLoanGrades, DataReader oReader) { base.SetObjectID(oLoanGrades, oReader.GetInt32("LoanGradesID").Value); oLoanGrades.LoanID = oReader.GetString("LoanID") == null ? 0 : oReader.GetInt32("LoanID").Value; oLoanGrades.LoanParameterID = oReader.GetString("LoanParameterID") == null ? 0 : oReader.GetInt32("LoanParameterID").Value; oLoanGrades.GradeID = oReader.GetString("GradeID") == null ? 0 : oReader.GetInt32("GradeID").Value; this.SetObjectState(oLoanGrades, Ease.Core.ObjectState.Saved); } protected List CreateLoanGradesObject(DataReader oReader) { List oLoanGrades = new List(); while (oReader.Read()) { LoanGrades oLoanGrade = new LoanGrades(); MapLoanGrades(oLoanGrade, oReader); oLoanGrades.Add(oLoanGrade); } return oLoanGrades; } #endregion #region MaoObject For LoanDoc private void MapLoanDocs(LoanDoc oLoanDocs, DataReader oReader) { base.SetObjectID(oLoanDocs, oReader.GetInt32("LoanDocsID").Value); oLoanDocs.HRDocID = oReader.GetString("HRDocID") == null ? 0 : oReader.GetInt32("HRDocID").Value; oLoanDocs.LoanID = oReader.GetString("LoanID") == null ? 0 : oReader.GetInt32("LoanID").Value; oLoanDocs.LoanParameterID = oReader.GetString("LoanParameterID") == null ? 0 : oReader.GetInt32("LoanParameterID").Value; this.SetObjectState(oLoanDocs, Ease.Core.ObjectState.Saved); } protected List CreateLoanDocsObject(DataReader oReader) { List oLoanDocs = new List(); while (oReader.Read()) { LoanDoc oLoanDoc = new LoanDoc(); MapLoanDocs(oLoanDoc, oReader); oLoanDocs.Add(oLoanDoc); } return oLoanDocs; } #endregion #region Implement LoanParameter Service public LoanParameter Get(int id, int payrollTypeID) { LoanParameter oLoanParameter = new LoanParameter(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(LoanParameterDA.Get(tc, id, payrollTypeID)); if (oreader.Read()) { oLoanParameter = this.CreateObject(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 oLoanParameter; } public List Get(int payrollTypeID) { List LoanParameters = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LoanParameterDA.Get(tc, payrollTypeID)); LoanParameters = 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 LoanParameters; } public int Save(LoanParameter oLoanParameter, int payrollTypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oLoanParameter.IsNew) { int id = tc.GenerateID("LoanParameter", "LoanParameterID"); base.SetObjectID(oLoanParameter, id); LoanParameterDA.Insert(tc, oLoanParameter, payrollTypeID); } else { LoanParameterDA.Update(tc, oLoanParameter, payrollTypeID); LoanParameterDA.DeleteLoanGrade(tc, oLoanParameter.ID); LoanParameterDA.DeleteLoanDoc(tc, oLoanParameter.ID); } foreach (LoanGrades oLoanGrades in oLoanParameter.LoadGradesTemp) { oLoanGrades.LoanParameterID = oLoanParameter.ID; oLoanGrades.LoanID = oLoanParameter.LoanID; int loanGradeId = tc.GenerateID("LoanGrades", "LoanGradesID"); base.SetObjectID(oLoanGrades, loanGradeId); LoanParameterDA.InsertLoadGrades(tc, oLoanGrades); } foreach (LoanDoc docItem in oLoanParameter.LoadDocsTemp) { docItem.LoanParameterID = oLoanParameter.ID; docItem.LoanID = oLoanParameter.LoanID; int loanDocID = tc.GenerateID("LoanDocs", "LoanDocsID"); base.SetObjectID(docItem, loanDocID); LoanParameterDA.InsertDocItem(tc, docItem); } tc.End(); return oLoanParameter.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); LoanParameterDA.DeleteLoanGrade(tc, id); LoanParameterDA.DeleteLoanDoc(tc, id); LoanParameterDA.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 #region Implement LoanGrade Service public List GetLoanGrades(int loanParameterID) { List loanGradess = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LoanParameterDA.GetLoanGrades(tc, loanParameterID)); loanGradess = this.CreateLoanGradesObject(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 loanGradess; } public List GetLoanDoc(int loanParameterID) { List loanDocs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LoanParameterDA.GetLoanDoc(tc, loanParameterID)); loanDocs = this.CreateLoanDocsObject(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 loanDocs; } #endregion } #endregion }