using System; using System.Data; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core; using System.Collections.Generic; using Ease.Core.Utility; using HRM.BO; using HRM.DA; namespace HRM.DA.Fund { public class InvestmentScheduleService : ServiceTemplate, IInvestmentScheduleService { #region Private functions and declaration public InvestmentScheduleService() { } private void MapObject(InvestmentSchedule oInvestmentSchedule, DataReader oReader) { base.SetObjectID(oInvestmentSchedule, oReader.GetInt32("ID").Value); oInvestmentSchedule.FromDate = oReader.GetDateTime("FromDate").Value; oInvestmentSchedule.InvestmentID = oReader.GetInt32("InvestmentID").Value; oInvestmentSchedule.FundTypeID = oReader.GetInt32("FundTypeID").Value; oInvestmentSchedule.Percentage = oReader.GetFloat("Percentage").Value; oInvestmentSchedule.RecalculationNeeded = oReader.GetBoolean("RecalculationNeeded").Value; oInvestmentSchedule.TillDate = oReader.GetDateTime("TillDate").Value; oInvestmentSchedule.TranDate = oReader.GetDateTime("TranDate").Value; oInvestmentSchedule.CreatedBy = oReader.GetInt32("CreatedBy").Value; oInvestmentSchedule.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oInvestmentSchedule.ModifiedBy = oReader.GetInt32("ModifiedBy"); oInvestmentSchedule.ModifiedDate = oReader.GetDateTime("ModifiedDate"); base.SetObjectState(oInvestmentSchedule, ObjectState.Modified); } private InvestmentSchedule CreateObject(DataReader oReader) { InvestmentSchedule oInvestmentSchedule = new InvestmentSchedule(); MapObject(oInvestmentSchedule, oReader); return oInvestmentSchedule; } #endregion #region Service implementation public InvestmentSchedule Get(int id) { InvestmentSchedule oInvestmentSchedule = new InvestmentSchedule(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); IDataReader oreader = InvestmentScheduleDA.Get(tc, id); DataReader oReader = new DataReader(oreader); if (oreader.Read()) { oInvestmentSchedule = CreateObject(oReader); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetInvestmentSchedule", e); #endregion } #region Cache Footer #endregion return oInvestmentSchedule; } public List Get() { List items = new List(); items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dataReader = new DataReader(InvestmentScheduleDA.Get(tc)); items = this.CreateObjects(dataReader); dataReader.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 items; } public DataTable GetTable(int fundtypeid) { DataTable dataTable = new DataTable("InvestmentSchedule"); TransactionContext tc = null; try { tc = TransactionContext.Begin(); IDataReader iDataReader = InvestmentScheduleDA.Get(tc, fundtypeid); dataTable.Load(iDataReader); iDataReader.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 dataTable; } protected override T CreateObject(DataReader dataReader) { InvestmentSchedule investmentSchedule = new InvestmentSchedule(); MapObject(investmentSchedule, dataReader); return investmentSchedule as T; } public void Save(InvestmentSchedule oInvestmentSchedule) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oInvestmentSchedule.IsNew) { int id = tc.GenerateID("InvestmentSchedule", "ID"); base.SetObjectID(oInvestmentSchedule, (id)); InvestmentScheduleDA.Insert(tc, oInvestmentSchedule); } else { InvestmentScheduleDA.Update(tc, oInvestmentSchedule); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetInvestmentSchedule", e); #endregion } } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); InvestmentScheduleDA.Delete(tc, id); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetInvestmentSchedule", e); #endregion } } #endregion } }