using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; using System; using System.Collections.Generic; namespace HRM.DA { public class FundBranchService : ServiceTemplate, IFundBranchService { private void MapObject(FundBranch oFundBranch, DataReader oReader) { base.SetObjectID(oFundBranch, oReader.GetInt32("BRANCHID").Value); oFundBranch.Code = oReader.GetString("BRANCHCODE"); oFundBranch.Name = oReader.GetString("BRANCHNAME"); oFundBranch.Address = oReader.GetString("ADDRESS"); oFundBranch.BankID = oReader.GetInt32("BANKID").Value; oFundBranch.Telephone = oReader.GetString("CONTACTNO"); oFundBranch.FaxNo = oReader.GetString("FAX"); oFundBranch.RoutingNo = oReader.GetInt32("RoutingNo").Value; oFundBranch.FundTypeID = oReader.GetInt32("FundTypeID").Value; } protected override T CreateObject(DataReader dr) { FundBranch oFundBranch = new FundBranch(); MapObject(oFundBranch, dr); return oFundBranch as T; } protected FundBranch CreateObject(DataReader oReader) { FundBranch oBranch = new FundBranch(); MapObject(oBranch, oReader); return oBranch; } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); FundBranchDA.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 } } public FundBranch Get(int id) { FundBranch oFundBranch = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(FundBranchDA.Get(tc, id)); if (oreader.Read()) { oFundBranch = 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 oFundBranch; } public List GetFundbranches(EnumStatus status) { List oFundBranch = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FundBranchDA.Get(tc)); oFundBranch = 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 oFundBranch; } public string GetNextCode() { throw new NotImplementedException(); } public int Save(FundBranch oBranch) { TransactionContext tc = null; try { int nID = oBranch.ID; tc = TransactionContext.Begin(true); if (oBranch.IsNew) { int id = tc.GenerateID("FM_BRANCH", "BranchID"); base.SetObjectID(oBranch, id); FundBranchDA.Insert(tc, oBranch); } else { FundBranchDA.Update(tc, oBranch); } tc.End(); return oBranch.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List Get() { List banks = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FundBranchDA.Get(tc)); banks = 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 banks; } public List GetBranchByFundTypeID(int fundTypeID) { List banks = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FundBranchDA.GetByFundTypeID(tc,fundTypeID)); banks = 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 banks; } public List GetBranchByBankID(int bankID) { List banks = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FundBranchDA.GetByBankID(tc, bankID)); banks = 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 banks; } } }