using System; using System.Collections.Generic; using System.Data; using System.Linq; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { public class FMLoanCategoryService : ServiceTemplate , IFMLoanCategoryService { public FMLoanCategoryService() { } #region Function #region Child Function //private void MapFundRelation(LoanCategory.LoanCategoryFundRelation fundRelation, DataReader dr) //{ // fundRelation.LoanCategoryID = dr.GetID("LoanCategoryID"); // fundRelation.FundTypeID = dr.GetID("FundTypeID"); // fundRelation.ProjectID = dr.GetID("ProjectID"); // base.SetObjectID(fundRelation, dr.GetID("LoanCategoryID", "FundTypeID")); // base.SetObjectState(fundRelation, ObjectState.Saved); //} //private LoanCategory.LoanCategoryFundRelation CreateFundRelations(DataReader dr) //{ // LoanCategory.LoanCategoryFundRelation fundRelation = new LoanCategory.LoanCategoryFundRelation(); // MapFundRelation(fundRelation, dr); // return fundRelation; //} //private void FillFundRelations(LoanCategory parent, DataReader dr) //{ // while (dr.Read()) // { // LoanCategory.LoanCategoryFundRelation item = this.CreateFundRelations(dr); // parent.LoanFundRelations.Add(item); // } //} //internal void loadChildren(TransactionContext tc, LoanCategory loanCategory) //{ // try // { // if (loanCategory != null && loanCategory.ID != null && loanCategory.ID != 0) // { // //Get FundRelations // DataReader dr = new DataReader(LoanCategoryDA.GetFundRelations(tc, loanCategory.ID)); // FillFundRelations(loanCategory, dr); // dr.Close(); // } // } // catch (Exception e) // { // throw e; // } //} #endregion private void MapObject(FMLoanCategory loanCategory, DataReader dr) { base.SetObjectID(loanCategory, dr.GetInt32("LoanCategoryID").Value); loanCategory.DefaultInterestRate = dr.GetDouble("DefaultInterestRate").Value; loanCategory.LoanCategoryCode = dr.GetString("LoanCategoryCode"); loanCategory.Description = dr.GetString("Description"); loanCategory.UserObjectName = dr.GetString("UserObjectName"); loanCategory.IsActive = (EnumFMLoanCategoryStatus)dr.GetInt16("IsActive").Value; loanCategory.MaxAlowableFlatAmount = dr.GetDouble("MaxAlowableFlatAmount"); loanCategory.MaxInstallment = dr.GetInt32("MaxInstallment").Value; loanCategory.MinInstallment = dr.GetInt32("MinInstallment").Value; loanCategory.PercentageofFund = dr.GetDouble("PercentageofFund"); loanCategory.Version = dr.GetInt16("Version").Value; loanCategory.CreatedBy = dr.GetInt32("CreatedBy").Value; loanCategory.CreatedDate = dr.GetDateTime("CreatedDate").Value; loanCategory.ModifiedBy = dr.GetInt32("ModifiedBy"); loanCategory.ModifiedDate = dr.GetDateTime("ModifiedDate"); loanCategory.FundTypeID = dr.GetInt32("FundTypeID").Value; loanCategory.calculationMethod =dr.GetInt32("calculationMethod") == null ? 0 : (EnumLoanCalMethod)dr.GetInt32("calculationMethod").Value; loanCategory.IsReceiveInterestInSettlement = dr.GetBoolean("IsReceiveInterestInSettlement") == null? 0 : dr.GetInt32("IsReceiveInterestInSettlement").Value; loanCategory.EarlySettleCharge = dr.GetInt32("EarlySettleCharge") == null ? 0 : dr.GetInt32("EarlySettleCharge").Value; loanCategory.fractionCaltype =dr.GetInt32("fractionCaltype") == null ? 0 : (EnumLoanFraction)dr.GetInt32("fractionCaltype").Value; base.SetObjectState(loanCategory, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader dr) { FMLoanCategory loanCategory = new FMLoanCategory(); MapObject(loanCategory, dr); return loanCategory as T; } protected FMLoanCategory CreateObject(DataReader oReader) { FMLoanCategory loanCategory = new FMLoanCategory(); MapObject(loanCategory, oReader); return loanCategory; } #endregion public int Save(FMLoanCategory fMLoanCategory) { TransactionContext tc = null; try { int nID = fMLoanCategory.ID; tc = TransactionContext.Begin(true); if (fMLoanCategory.IsNew) { int id = tc.GenerateID("FM_LoanCategory", "LOANCATEGORYID"); base.SetObjectID(fMLoanCategory, id); FMLoanCategoryDA.Insert(tc, fMLoanCategory); } else { FMLoanCategoryDA.Update(tc, fMLoanCategory); } tc.End(); return fMLoanCategory.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #region Service Implementation #region Delete public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); FMLoanCategoryDA.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 Loan Category", e); #endregion } } #endregion #region Get() public List GetByFundType(int fundTypeID) { List loanCategory = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FMLoanCategoryDA.GetByFundType(tc, fundTypeID)); loanCategory = 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 loanCategory; } public FMLoanCategory GetbyID(int ID) { FMLoanCategory loan = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FMLoanCategoryDA.GetbyID(tc, ID)); if (dr.Read()) { loan = 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 loan; } public List Get() { List loanCategorys = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FMLoanCategoryDA.Get(tc)); loanCategorys = base.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 loanCategorys; } public List Get(EnumFMLoanCategoryStatus status) { List loanCategorys = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FMLoanCategoryDA.Get(tc, status)); loanCategorys = base.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 loanCategorys; } #endregion #region GetTable public DataTable GetTable() { DataTable dTbl = new DataTable("LoanCategorys"); //TransactionContext tc = null; //try //{ // tc = TransactionContext.Begin(); // IDataReader ir = LoanCategoryDA.Get(tc); // dTbl.Load(ir); // ir.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 dTbl; } #endregion #region Change Status public void ChangeStatus(FMLoanCategory loanCategory, EnumFMLoanCategoryStatus status) { TransactionContext tc = null; try { //int activeStatus = Convert.ToInt16(status); tc = TransactionContext.Begin(true); //loanCategory.Version = 1; FMLoanCategoryDA.ChangeStatus(tc, loanCategory, status); tc.End(); // CacheInfo.ClearCache(typeof(LoanCategoryService).FullName); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #region IsExists public bool IsExist(string code, int version) { bool exists = false; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); exists = FMLoanCategoryDA.IsExist(tc, code, version); tc.End(); } catch (Exception e) { throw new ServiceException("Failed to Check by code" + e.Message, e); } return exists; } #endregion #region IsIssued public bool IsIssued(int loancatID) { bool isIssued = false; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); isIssued = FMLoanCategoryDA.IsIssued(tc, loancatID); tc.End(); } catch (Exception e) { throw new ServiceException("Failed to Check by ID" + e.Message, e); } return isIssued; } #endregion #region Update Activity internal void UpdateActivityInfo(TransactionContext tc, int ActivityID, int RecordID) { try { FMLoanCategoryDA.UpdateActivity(tc, ActivityID, RecordID); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #endregion } }