EchoTex_Payroll/HRM.DA/Service/Survey/SurveyResultService.cs

453 lines
14 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
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 SurveyResultService : ServiceTemplate, ISurveyResultService
{
public SurveyResultService()
{
}
private void MapObject(SurveyResult oSurveyResult, DataReader oReader)
{
//base.SetObjectID(oSurveyResult, oReader.GetID("SurveyResultID"));
oSurveyResult.SurveyID = (oReader.GetInt32("SurveyID").Value);
oSurveyResult.AnswerID = oReader.GetInt32("AnswerID").GetValueOrDefault();
oSurveyResult.EmployeeID = oReader.GetInt32("EmployeeID").GetValueOrDefault();
oSurveyResult.QuestionID = oReader.GetInt32("QuestionID").GetValueOrDefault();
oSurveyResult.IsCorrect = oReader.GetBoolean("IsCorrect").GetValueOrDefault();
oSurveyResult.ForEmployeeID = oReader.GetInt32("ForEmployeeID").GetValueOrDefault();
oSurveyResult.Weight = oReader.GetDouble("Weight").GetValueOrDefault();
oSurveyResult.CandidateID = oReader.GetInt32("CandidateID").GetValueOrDefault();
this.SetObjectState(oSurveyResult, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
SurveyResult oSurveyResult = new SurveyResult();
MapObject(oSurveyResult, oReader);
return oSurveyResult as T;
}
protected SurveyResult CreateObject(DataReader oReader)
{
SurveyResult oSurveyResult = new SurveyResult();
MapObject(oSurveyResult, oReader);
return oSurveyResult;
}
#region Service implementation
public List<SurveyResult> GetSurveyResult(int surveyId)
{
List<SurveyResult> oSurveyResults = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyResultDA.GetSurveyResult(tc, surveyId));
oSurveyResults = this.CreateObjects<SurveyResult>(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 oSurveyResults;
}
public List<SurveyResult> GetSurveyResult()
{
List<SurveyResult> oSurveyResults = null;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyResultDA.GetSurveyResult(tc));
oSurveyResults = this.CreateObjects<SurveyResult>(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 oSurveyResults;
}
public List<SurveyResult> GetSurveyResult(int surveyId, string employeeIds)
{
List<SurveyResult> oSurveyResults = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyResultDA.GetSurveyResult(tc, surveyId, employeeIds));
oSurveyResults = this.CreateObjects<SurveyResult>(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 oSurveyResults;
}
public List<SurveyResult> GetSurveyResult(int surveyId, int employeeId, int questionID)
{
List<SurveyResult> oSurveyResults = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyResultDA.GetSurveyResult(tc, surveyId, employeeId, questionID));
oSurveyResults = this.CreateObjects<SurveyResult>(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 oSurveyResults;
}
public List<SurveyResult> GetSurveyResults(int surveyId, int candidateId)
{
List<SurveyResult> oSurveyResults = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyResultDA.GetSurveyResults(tc, surveyId, candidateId));
oSurveyResults = this.CreateObjects<SurveyResult>(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 oSurveyResults;
}
public SurveyResult GetSurveyResultByCandidateID(int surveyId, int candidateId, int questionID)
{
SurveyResult oSurveyResult = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyResultDA.GetSurveyResultByCandidateID(tc, surveyId, candidateId, questionID));
if (dr.Read())
{
oSurveyResult = this.CreateObject<SurveyResult>(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 oSurveyResult;
}
public void Save(List<SurveyResult> oSurveyResults)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (SurveyResult oSurveyResult in oSurveyResults)
{
SurveyResultDA.DeleteSurveyResult(tc, oSurveyResult.SurveyID, (int)oSurveyResult.EmployeeID,
oSurveyResult.QuestionID);
}
foreach (SurveyResult oSurveyResult in oSurveyResults)
{
//if (oSurveyResult.IsNew)
//{
//int id = tc.GenerateID("SurveyResult", "SurveyResultID");
//base.SetObjectID(oSurveyResult, (id));
SurveyResultDA.Insert(tc, oSurveyResult);
//}
//else
//{
// SurveyResultDA.Update(tc, oSurveyResult);
//}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(SurveyResult oSurveyResult)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oSurveyResult.IsNew)
{
//int id = tc.GenerateID("SurveyResult", "SurveyResultID");
//base.SetObjectID(oSurveyResult, (id));
SurveyResultDA.Insert(tc, oSurveyResult);
}
else
{
SurveyResultDA.Update(tc, oSurveyResult);
}
tc.End();
return oSurveyResult.SurveyID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
internal int getHitCount(TransactionContext tc, int surveyID, int questionID, int answerID)
{
return SurveyAnswerCountDA.GetSurveyAnswerHitCount(tc, surveyID, questionID, answerID);
}
public void SaveSurveyResult(SurveyResult oSurveyResult, SurveyEmployee surEmp, bool IsAnnonymous,
int GeneralNoticeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
SurveyEmployeeDA.UpdateSurveyEmployee(tc, surEmp);
if (IsAnnonymous)
SurveyResultDA.Insert(tc, oSurveyResult);
if (getHitCount(tc, oSurveyResult.SurveyID, oSurveyResult.QuestionID, oSurveyResult.AnswerID) > 0)
SurveyAnswerCountDA.UpdateSurveyAnswerCount(tc, oSurveyResult.SurveyID, oSurveyResult.QuestionID,
oSurveyResult.AnswerID);
else
SurveyAnswerCountDA.InsertSurveyAnswerCount(tc, oSurveyResult.SurveyID, oSurveyResult.QuestionID,
oSurveyResult.AnswerID);
//GeneralNoticeDA.Delete(tc, GeneralNoticeID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Insert Survey Result.", e);
#endregion
}
}
public void SaveSurveyResult(List<SurveyResult> oSurveyResults, SurveyEmployee surEmp, bool IsAnnonymous,
int GeneralNoticeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
//update the assessment date of the employee or manager.
SurveyEmployeeDA.UpdateSurveyEmployee(tc, surEmp);
foreach (SurveyResult oSurveyResult in oSurveyResults)
{
if (!IsAnnonymous)
{
SurveyResultDA.DeleteSurveyResult(tc, oSurveyResult.SurveyID, (int)oSurveyResult.EmployeeID,
oSurveyResult.QuestionID);
SurveyResultDA.InsertSurveyResult(tc, oSurveyResult);
}
if (getHitCount(tc, oSurveyResult.SurveyID, oSurveyResult.QuestionID, oSurveyResult.AnswerID) > 0)
SurveyAnswerCountDA.UpdateSurveyAnswerCount(tc, oSurveyResult.SurveyID,
oSurveyResult.QuestionID, oSurveyResult.AnswerID);
else
SurveyAnswerCountDA.InsertSurveyAnswerCount(tc, oSurveyResult.SurveyID,
oSurveyResult.QuestionID, oSurveyResult.AnswerID);
}
//GeneralNoticeDA.Delete(tc, GeneralNoticeID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Insert Survey Result.", e);
#endregion
}
}
public DataSet GetSurveyResultReport(int surveyID)
{
DataSet ds = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
ds = SurveyResultDA.GetSurveyResultReport(tc, surveyID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Report", e);
#endregion
}
return ds;
}
public void Delete(int id)
{
//TransactionContext tc = null;
//try
//{
// tc = TransactionContext.Begin(true);
// SurveyResultDA.DeleteSurveyResult(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 questionID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
SurveyResultDA.DeleteSurveyResultByCandidateID(tc, surveyId, questionID, candidateId);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
}
}