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 SurveyEmployeeService : ServiceTemplate, ISurveyEmployeeService { #region Private functions and declaration Cache _cache = new Cache(typeof(SurveyEmployee)); #endregion public SurveyEmployeeService() { } private void MapObject(SurveyEmployee oSurveyEmployee, DataReader oReader) { // base.SetObjectID(oSurveyEmployee, oReader.GetID("SurveyEmployeeID")); oSurveyEmployee.SurveyID = oReader.GetID("SurveyID"); oSurveyEmployee.EmployeeID = oReader.GetInt32("EmployeeID").GetValueOrDefault(); this.SetObjectState(oSurveyEmployee, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { SurveyEmployee oSurveyEmployee = new SurveyEmployee(); MapObject(oSurveyEmployee, oReader); return oSurveyEmployee as T; } #region Service implementation public ObjectsTemplate GetSurveyEmployee(ID surveyId) { #region Cache Header ObjectsTemplate oSurveyEmployees = _cache["GetSurveyEmployee",surveyId] as ObjectsTemplate; if (oSurveyEmployees != null) return oSurveyEmployees; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyEmployeeDA.GetSurveyEmployee(tc,surveyId.Integer)); oSurveyEmployees = 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(oSurveyEmployees, "GetSurveyEmployee", surveyId); #endregion return oSurveyEmployees; } public ObjectsTemplate GetSurveyEmployee() { #region Cache Header ObjectsTemplate oSurveyEmployees = _cache["GetSurveyEmployee"] as ObjectsTemplate; if (oSurveyEmployees != null) return oSurveyEmployees; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyEmployeeDA.GetSurveyEmployee(tc)); oSurveyEmployees = 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(oSurveyEmployees, "GetSurveyEmployee"); #endregion return oSurveyEmployees; } public ID Save(SurveyEmployee oSurveyEmployee) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oSurveyEmployee.IsNew) { //int id = tc.GenerateID("SurveyEmployee", "SurveyEmployeeID"); //base.SetObjectID(oSurveyEmployee, ID.FromInteger(id)); SurveyEmployeeDA.Insert(tc, oSurveyEmployee); } else { SurveyEmployeeDA.Update(tc, oSurveyEmployee); } tc.End(); return oSurveyEmployee.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); SurveyEmployeeDA.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 } }