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 { public class SurveyOrganizationService : ServiceTemplate, ISurveyOrganizationService { public SurveyOrganizationService() { } private void MapObject(SurveyOrganization oSurveyOrganization, DataReader oReader) { //base.SetObjectID(oSurveyOrganization, oReader.GetID("SurveyOrganizationID")); oSurveyOrganization.SurveyID = oReader.GetInt32("SurveyID", 0); oSurveyOrganization.GradeID = oReader.GetInt32("GradeID", 0); oSurveyOrganization.CompanyID = oReader.GetInt32("CompanyID", 0); oSurveyOrganization.DepartmentID = oReader.GetInt32("DepartmentID", 0); oSurveyOrganization.LocationID = oReader.GetInt32("LocationID", 0); this.SetObjectState(oSurveyOrganization, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { SurveyOrganization oSurveyOrganization = new SurveyOrganization(); MapObject(oSurveyOrganization, oReader); return oSurveyOrganization as T; } protected SurveyOrganization CreateObject(DataReader oReader) { SurveyOrganization oSurveyOrganization = new SurveyOrganization(); MapObject(oSurveyOrganization, oReader); return oSurveyOrganization; } #region Service implementation public List GetSurveyOrganization(int surveyId) { List oSurveyOrganizations = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyOrganizationDA.GetSurveyOrganization(tc, surveyId)); oSurveyOrganizations = 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 oSurveyOrganizations; } public SurveyOrganization Get(int id) { SurveyOrganization oSurveyOrganization = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(SurveyOrganizationDA.Get(tc, id)); if (oreader.Read()) { oSurveyOrganization = 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 oSurveyOrganization; } public List Get() { List SurveyOrganizations = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyOrganizationDA.Get(tc)); SurveyOrganizations = 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 SurveyOrganizations; } public List Get(EnumStatus status) { List SurveyOrganizations = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyOrganizationDA.Get(tc, status)); SurveyOrganizations = 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 SurveyOrganizations; } public int Save(SurveyOrganization oSurveyOrganization) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oSurveyOrganization.IsNew) { //int id = tc.GenerateID("SurveyOrganization", "SurveyOrganizationID"); //base.SetObjectID(oSurveyOrganization, (id)); SurveyOrganizationDA.Insert(tc, oSurveyOrganization); } else { SurveyOrganizationDA.Update(tc, oSurveyOrganization); } tc.End(); return oSurveyOrganization.SurveyID; } 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); SurveyOrganizationDA.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 } }