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 SurveyEmployeeService : ServiceTemplate, ISurveyEmployeeService { public SurveyEmployeeService() { } private void MapObject(SurveyEmployee oSurveyEmployee, DataReader oReader) { base.SetObjectID(oSurveyEmployee, oReader.GetInt32("SurveyEmployeeID").Value); oSurveyEmployee.SurveyID = oReader.GetInt32("SurveyID").Value; oSurveyEmployee.participantID = oReader.GetInt32("participantID").GetValueOrDefault(); oSurveyEmployee.ReferenceID = oReader.GetInt32("ReferenceID").Value; oSurveyEmployee.surveyType = (EnumSurveyType)(int)oReader.GetInt32("surveyType").Value; oSurveyEmployee.StartTime = oReader.GetDateTime("STARTTIME").Value; oSurveyEmployee.lastUpdateTime = oReader.GetDateTime("lastUpdateTime"); oSurveyEmployee.SpendTime = oReader.GetDouble("SpendTime").Value; oSurveyEmployee.CurrentQuestionID = oReader.GetInt32("CurrentQuestionID"); oSurveyEmployee.SurveyMark = oReader.GetDouble("SurveyMark").Value; oSurveyEmployee.PassMark = oReader.GetDouble("PassMark").Value; oSurveyEmployee.ReceiveMark = oReader.GetDouble("ReceiveMark").Value; oSurveyEmployee.IsCompleted = oReader.GetBoolean("IsCompleted").Value; oSurveyEmployee.CompleteTime = oReader.GetDateTime("CompleteTime"); oSurveyEmployee.IsCancel = oReader.GetBoolean("IsCompleted").Value; oSurveyEmployee.CancelReason = oReader.GetString("CancelReason"); oSurveyEmployee.CancelDate = oReader.GetDateTime("CancelDate"); this.SetObjectState(oSurveyEmployee, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { SurveyEmployee oSurveyEmployee = new SurveyEmployee(); MapObject(oSurveyEmployee, oReader); return oSurveyEmployee as T; } #region Service implementation public List GetSurveyEmployee(int surveyId) { List oSurveyEmployees = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyEmployeeDA.GetSurveyEmployee(tc, surveyId)); 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 } return oSurveyEmployees; } public List GetSurveyEmployee() { List oSurveyEmployees = null; 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 } return oSurveyEmployees; } public int Save(SurveyEmployee oSurveyEmployee) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oSurveyEmployee.IsNew) { int id = tc.GenerateID("SurveyEmployee", "SurveyEmployeeID"); base.SetObjectID(oSurveyEmployee, (id)); SurveyEmployeeDA.Insert(tc, oSurveyEmployee); } else { SurveyEmployeeDA.Update(tc, oSurveyEmployee); } SurveyResultService os = new SurveyResultService(); // int newid = tc.GenerateID("SurveyResult", "SurveyResultID"); SurveyResultDA.DeleteBySurveyEmployee(tc, (int) oSurveyEmployee.ID); foreach (var item in oSurveyEmployee.Results) { //newid = newid + 1; //base.SetObjectID(item, (newid)); item.surveyEmployeeID = oSurveyEmployee.ID; item.participantID = oSurveyEmployee.participantID; os.Save(tc, item); } 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 int SubmitSurvey(SurveyEmployee oSurveyEmployee) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); 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 UpdateSpendTime(SurveyEmployee oSurveyEmployee) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); SurveyEmployeeDA.UpdateSpendTime(tc, oSurveyEmployee); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Cancel(SurveyEmployee oSurveyEmployee) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); SurveyEmployeeDA.Cancel(tc, oSurveyEmployee); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public SurveyEmployee GetNotCompletedSurveyByparticipentID(int surveyId, int participentID, int referenceID) { SurveyEmployee oSurveyEmployee = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyEmployeeDA.GetNotCompletedSurveyByparticipentID(tc, surveyId, participentID, referenceID)); if (dr.Read()) { oSurveyEmployee = this.CreateObject(dr); } dr.Close(); if (oSurveyEmployee !=null) { oSurveyEmployee.Results = new SurveyResultService().GetResultBySurveyEmployeeID(tc, oSurveyEmployee.ID); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oSurveyEmployee; } public List GetSurveyEmployeeByCandidateId(int surveyId, int candidateId) { List oSurveyEmployees = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyEmployeeDA.GetSurveyEmployeebycandidateId(tc, surveyId, candidateId)); 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 } return oSurveyEmployees; } public List GetSurveyEmployeebyJobId(int candidateId, int erCircularId) { List oSurveyEmployees = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyEmployeeDA.GetSurveyEmployeebyJobId(tc, candidateId, erCircularId)); 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 } return oSurveyEmployees; } public List GetCompleteExamByCandidate(int candidateId, int erCircularId) { List oSurveyEmployees = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(SurveyEmployeeDA.GetCompleteExamByCandidate(tc, candidateId, erCircularId)); 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 } return oSurveyEmployees; } public void Delete(int 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 } } public void DeleteByCandidateID(int surveyId, int candidateId,int erCircularId) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); SurveyEmployeeDA.DeleteSurveyEmployeeByCandidateID(tc, surveyId, candidateId, erCircularId); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion } }