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 System.IO; using System.Linq; namespace HRM.DA { public class ErCircularSurveyService : ServiceTemplate, IErCircularSurveyService { #region ErCircularService Object Mapping private void MapErCricularObject(ErCircularSurvey obErCircular, DataReader oReader) { this.SetObjectID(obErCircular, oReader.GetInt32("ERSurveyCircularID").Value); obErCircular.SurveyID = oReader.GetInt32("SurveyID", 0); obErCircular.ERCircularID = oReader.GetInt32("ERCircularID", 0); this.SetObjectState(obErCircular, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ErCircularSurvey obErCircular = new ErCircularSurvey(); MapErCricularObject(obErCircular, oReader); return obErCircular as T; } private ErCircularSurvey CreateObject(DataReader oReader) { ErCircularSurvey obErCircular = new ErCircularSurvey(); MapErCricularObject(obErCircular, oReader); return obErCircular; } #endregion #region Service Implementation #region Insert(ErCircular erCricular) public void Save(ErCircularSurvey erCricularDetail) { TransactionContext tc = null; int oID = 0; try { tc = TransactionContext.Begin(true); if (erCricularDetail.IsNew) { int id = tc.GenerateID("ER_CircularSurvey", "ERSurveyCircularID"); oID = (id); base.SetObjectID(erCricularDetail, (id)); ErCircularSurveyDA.InsertErCircularSurvey(erCricularDetail, tc); } else { oID = erCricularDetail.ID; ErCircularSurveyDA.UpdateErCircularSurvey(erCricularDetail, tc); } tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } } #endregion #region GetReferredBy(int cVID) public List Get() { List allRefs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ErCircularSurveyDA.Get(tc)); allRefs = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allRefs; } public List GetByParentId(int parentId) { List allRefs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ErCircularSurveyDA.GetBySurveyID(tc, parentId)); allRefs = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allRefs; } public List GetByCircularID(int erCricularID) { List allRefs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ErCircularSurveyDA.GetByCircularID(tc, erCricularID)); allRefs = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allRefs; } public List GetByErCircularID(int erCircularID) { List allRefs = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ErCircularSurveyDA.GetByErCircularID(tc, erCircularID)); allRefs = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return allRefs; } #endregion #region Get(int cVID) public ErCircularSurvey Get(int erCircularDetailID) { ErCircularSurvey cv = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ErCircularSurveyDA.Get(tc, erCircularDetailID)); if (oreader.Read()) { cv = this.CreateObject(oreader); } oreader.Close(); tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } return cv; } #endregion public void Delete(ErCircularSurvey oErCircularDetail) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); #region Delete ErCircular ErCircularDetailDA.Delete(oErCircularDetail.ID, tc); #endregion tc.End(); } catch (Exception ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message, ex); #endregion } } #endregion } }