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; using System; using System.Data; namespace HRM.DA { public class SurveyWeightDefinitionService : ServiceTemplate, ISurveyWeightDefinitionService { public SurveyWeightDefinitionService() { } private void MapObject(SurveyWeightDefinition oSurveyWeightDefinition, DataReader oReader) { oSurveyWeightDefinition.SurveyID = oReader.GetInt32("SurveyID", 0); oSurveyWeightDefinition.FromWeight = oReader.GetDouble("FromWeight").Value; oSurveyWeightDefinition.ToWeight = oReader.GetDouble("ToWeight").Value; oSurveyWeightDefinition.Remark = oReader.GetString("Remark"); this.SetObjectState(oSurveyWeightDefinition, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { SurveyWeightDefinition oSurveyWeightDefinition = new SurveyWeightDefinition(); MapObject(oSurveyWeightDefinition, oReader); return oSurveyWeightDefinition as T; } #region Service implementation public List GetSurveyWeightDefinition(int surveyId) { List oSurveyWeightDefinitions = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyWeightDefinitionDA.GetSurveyWeightDefinition(tc, surveyId)); oSurveyWeightDefinitions = 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 oSurveyWeightDefinitions; } public List GetSurveyWeightDefinition() { List oSurveyWeightDefinitions = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyWeightDefinitionDA.GetSurveyWeightDefinition(tc)); oSurveyWeightDefinitions = 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 oSurveyWeightDefinitions; } public int Save(SurveyWeightDefinition oSurveyWeightDefinition) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); SurveyWeightDefinitionDA.DeleteSurveyWeightDefinition(tc, oSurveyWeightDefinition.SurveyID); SurveyWeightDefinitionDA.Insert(tc, oSurveyWeightDefinition); tc.End(); return oSurveyWeightDefinition.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); SurveyWeightDefinitionDA.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 } }