using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using Ease.Core; using HRM.BO; using System; using System.Collections.Generic; using System.Data; using static HRM.BO.RDReport; namespace HRM.DA { public class RDReportService : ServiceTemplate, IRDReportService { #region Private functions and declaration public RDReportService() { } private void MapObject(RDReport oRDReport, DataReader oReader) { this.SetObjectID(oRDReport,oReader.GetInt32("REPORTID").Value); oRDReport.ReportCode = oReader.GetString("REPORTCODE"); oRDReport.ReportName = oReader.GetString("REPORTNAME"); oRDReport.ReportType = (EnumReportTypes)oReader.GetInt32("REPORTTYPE"); this.SetObjectState(oRDReport, ObjectState.Saved); } //private RDReport CreateObject(DataReader oReader) //{ // RDReport oRDReport = new RDReport(); // MapObject(oRDReport, oReader); // return oRDReport; //} protected override T CreateObject(DataReader oReader) { RDReport oRDReport = new RDReport(); MapObject(oRDReport, oReader); return oRDReport as T; } #endregion #region Service implementation public bool IsExistCode(string code,int fundTypeID) { bool exist = false; TransactionContext tc = null; try { tc = TransactionContext.Begin(); exist = RDReportDA.IsExistCode(tc, code, fundTypeID); tc.End(); } catch (Exception e) { if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); } return exist; } public bool IsExistType(EnumReportType reportType, int fundTypeID) { bool exist = false; TransactionContext tc = null; try { tc = TransactionContext.Begin(); exist = RDReportDA.IsExistType(tc, reportType, fundTypeID); tc.End(); } catch (Exception e) { if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); } return exist; } public RDReport Get(int id) { RDReport oRDReport = new RDReport(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); IDataReader oreader = RDReportDA.Get(tc, id); DataReader oReader = new DataReader(oreader); if (oreader.Read()) { oRDReport = this.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 GetRDReport", e); #endregion } return oRDReport; } public RDReport GetByReportType(EnumReportType reportType) { RDReport oRDReport = new RDReport(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); IDataReader oreader = RDReportDA.Get(tc, reportType); DataReader oReader = new DataReader(oreader); if (oreader.Read()) { oRDReport = this.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 GetRDReport", e); #endregion } return oRDReport; } public List GetByFundTypeID(int fundTypeID) { List oRDReports = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oReader =new DataReader(RDReportDA.GetByFundType(tc, fundTypeID)); oRDReports = CreateObjects(oReader); oReader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Get RDReport", e); #endregion } return oRDReports; } public int Save(RDReport oRDReport, int fundTypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oRDReport.IsNew) { this.SetObjectID(oRDReport, (RDReportDA.GetNewID(tc))); RDReportDA.Insert(tc, oRDReport, fundTypeID); } else { RDReportDA.Update(tc, oRDReport, fundTypeID); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Save RDReport", e); #endregion } return oRDReport.ID; } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); RDReportDA.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 RDReport", e); #endregion } } public RDReport GetByReportTypeAndFundTypeID(EnumReportTypes reportType, int fundTypeID) { RDReport oRDReport = new RDReport(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); IDataReader oreader = RDReportDA.GetByReportTypeAndFundTypeID(tc, reportType, fundTypeID); DataReader oReader = new DataReader(oreader); if (oreader.Read()) { oRDReport = this.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 GetRDReport", e); #endregion } return oRDReport; } #endregion } }