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 SurveyAnswerCountService : ServiceTemplate, ISurveyAnswerCountService { public SurveyAnswerCountService() { } private void MapObject(SurveyAnswerCount oSurveyAnswerCount, DataReader oReader) { //base.SetObjectID(oSurveyAnswerCount, oReader.GetID("SurveyAnswerCountID")); oSurveyAnswerCount.SurveyID = oReader.GetInt32("SurveyID", 0); oSurveyAnswerCount.QuestionID = oReader.GetInt32("QuestionID").GetValueOrDefault(); oSurveyAnswerCount.AnswerID = oReader.GetInt32("AnswerID").GetValueOrDefault(); oSurveyAnswerCount.HitCount = oReader.GetInt32("HitCount").GetValueOrDefault(); this.SetObjectState(oSurveyAnswerCount, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { SurveyAnswerCount oSurveyAnswerCount = new SurveyAnswerCount(); MapObject(oSurveyAnswerCount, oReader); return oSurveyAnswerCount as T; } protected SurveyAnswerCount CreateObject(DataReader oReader) { SurveyAnswerCount oSurveyAnswerCount = new SurveyAnswerCount(); MapObject(oSurveyAnswerCount, oReader); return oSurveyAnswerCount; } #region Service implementation public List GetSurveyAnswerCount() { List oSurveyAnswerCounts = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyAnswerCountDA.GetSurveyAnswerCount(tc)); oSurveyAnswerCounts = 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 oSurveyAnswerCounts; } public List GetSurveyAnswerCount(int surveyId) { List oSurveyAnswerCounts = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyAnswerCountDA.GetSurveyAnswerCount(tc, surveyId)); oSurveyAnswerCounts = 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 oSurveyAnswerCounts; } public SurveyAnswerCount GetSurveyAnswerCount(int surveyId, int nQuestionId, int nAnswerId) { SurveyAnswerCount oSurveyAnswerCount = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(SurveyAnswerCountDA.GetSurveyAnswerCount(tc, surveyId, nQuestionId, nAnswerId)); if (oreader.Read()) { oSurveyAnswerCount = 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 Get SurveyAnswerCount", e); #endregion } return oSurveyAnswerCount; } public int Save(SurveyAnswerCount oSurveyAnswerCount) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oSurveyAnswerCount.IsNew) { //int id = tc.GenerateID("SurveyAnswerCount", "SurveyAnswerCountID"); //base.SetObjectID(oSurveyAnswerCount, (id)); SurveyAnswerCountDA.Insert(tc, oSurveyAnswerCount); } else { SurveyAnswerCountDA.Update(tc, oSurveyAnswerCount); } tc.End(); return oSurveyAnswerCount.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); SurveyAnswerCountDA.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 } }