using System; using System.Collections.Generic; using System.Linq; using System.Text; using Payroll.BO; using System.Data; using Ease.CoreV35.Model; using System.Data.SqlClient; using Ease.CoreV35.DataAccess; using Ease.CoreV35.DataAccess.SQL; using Ease.CoreV35.Caching; namespace Payroll.Service { [Serializable] public class SurveyQuestionService : ServiceTemplate, ISurveyQuestionService { #region Private functions and declaration Cache _cache = new Cache(typeof(SurveyQuestion)); #endregion public SurveyQuestionService() { } private void MapObject(SurveyQuestion oSurveyQuestion, DataReader oReader) { //base.SetObjectID(oSurveyQuestion, oReader.GetID("SurveyQuestionID")); oSurveyQuestion.SurveyID = oReader.GetID("SurveyID"); oSurveyQuestion.QuestionID = oReader.GetInt32("QuestionID").GetValueOrDefault(); this.SetObjectState(oSurveyQuestion, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { SurveyQuestion oSurveyQuestion = new SurveyQuestion(); MapObject(oSurveyQuestion, oReader); return oSurveyQuestion as T; } #region Service implementation public ObjectsTemplate GetSurveyQuestion(ID surveyId) { #region Cache Header ObjectsTemplate oSurveyQuestions = _cache["GetSurveyQuestion",surveyId] as ObjectsTemplate; if (oSurveyQuestions != null) return oSurveyQuestions; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyQuestionDA.GetSurveyQuestion(tc,surveyId.Integer)); oSurveyQuestions = 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 } #region Cache Footer _cache.Add(oSurveyQuestions, "GetSurveyQuestion", surveyId); #endregion return oSurveyQuestions; } public ObjectsTemplate GetSurveyQuestion() { #region Cache Header ObjectsTemplate oSurveyQuestions = _cache["GetSurveyQuestion"] as ObjectsTemplate; if (oSurveyQuestions != null) return oSurveyQuestions; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyQuestionDA.GetSurveyQuestion(tc)); oSurveyQuestions = 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 } #region Cache Footer _cache.Add(oSurveyQuestions, "GetSurveyQuestion"); #endregion return oSurveyQuestions; } public ID Save(SurveyQuestion oSurveyQuestion) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oSurveyQuestion.IsNew) { //int id = tc.GenerateID("SurveyQuestion", "SurveyQuestionID"); //base.SetObjectID(oSurveyQuestion, ID.FromInteger(id)); SurveyQuestionDA.Insert(tc, oSurveyQuestion); } else { SurveyQuestionDA.Update(tc, oSurveyQuestion); } tc.End(); return oSurveyQuestion.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(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); SurveyQuestionDA.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 } }