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 System.IO; using System.Data.SqlClient; using HRM.BO; namespace HRM.DA { public class ReportAuthorizationService : ServiceTemplate, IReportAuthorizationService { public ReportAuthorizationService() { } private void MapObject(ReportAuthorization oReportAuthorization, DataReader oReader) { base.SetObjectID(oReportAuthorization, (oReader.GetInt32("reportID").Value)); oReportAuthorization.AuthorizePersionId = oReader.GetInt32("personID", 0); oReportAuthorization.Position = oReader.GetInt32("Position").Value; this.SetObjectState(oReportAuthorization, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ReportAuthorization oReportAuthorization = new ReportAuthorization(); MapObject(oReportAuthorization, oReader); return oReportAuthorization as T; } protected ReportAuthorization CreateObject(DataReader oReader) { ReportAuthorization oReportAuthorization = new ReportAuthorization(); MapObject(oReportAuthorization, oReader); return oReportAuthorization; } #region Service implementation public ReportAuthorization Get(int id) { ReportAuthorization oReportAuthorization = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ReportAuthorizationDA.Get(tc, id)); if (oreader.Read()) { oReportAuthorization = 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 oReportAuthorization; } public List GetByReportID(int reportID) { List reportAuthorizations = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ReportAuthorizationDA.Get(tc, reportID)); reportAuthorizations = 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 reportAuthorizations; } public ReportAuthorization Get(int reportID, int position) { ReportAuthorization oReportAuthorization = new ReportAuthorization(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ReportAuthorizationDA.Get(tc, reportID, position)); if (oreader.Read()) { oReportAuthorization = 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 oReportAuthorization; } public List Get() { List reportAuthorizations = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ReportAuthorizationDA.Get(tc)); reportAuthorizations = 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 reportAuthorizations; } public int Save(ReportAuthorization oReportAuthorization) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oReportAuthorization.IsNew) { ReportAuthorizationDA.Insert(tc, oReportAuthorization); } else { ReportAuthorizationDA.Update(tc, oReportAuthorization); } tc.End(); return oReportAuthorization.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); ReportAuthorizationDA.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 } }