HRM-10/HRM.DA/Service/Survey/SurveyEmployeeService.cs
Mohaimen Hasan 838b8d4480 first commit
2026-11-03 13:06:00 +06:00

392 lines
12 KiB
C#

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<T>(DataReader oReader)
{
SurveyEmployee oSurveyEmployee = new SurveyEmployee();
MapObject(oSurveyEmployee, oReader);
return oSurveyEmployee as T;
}
#region Service implementation
public List<SurveyEmployee> GetSurveyEmployee(int surveyId)
{
List<SurveyEmployee> oSurveyEmployees = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyEmployeeDA.GetSurveyEmployee(tc, surveyId));
oSurveyEmployees = this.CreateObjects<SurveyEmployee>(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<SurveyEmployee> GetSurveyEmployee()
{
List<SurveyEmployee> oSurveyEmployees = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyEmployeeDA.GetSurveyEmployee(tc));
oSurveyEmployees = this.CreateObjects<SurveyEmployee>(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<SurveyEmployee>(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<SurveyEmployee> GetSurveyEmployeeByCandidateId(int surveyId, int candidateId)
{
List<SurveyEmployee> oSurveyEmployees = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyEmployeeDA.GetSurveyEmployeebycandidateId(tc, surveyId, candidateId));
oSurveyEmployees = this.CreateObjects<SurveyEmployee>(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<SurveyEmployee> GetSurveyEmployeebyJobId(int candidateId, int erCircularId)
{
List<SurveyEmployee> oSurveyEmployees = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyEmployeeDA.GetSurveyEmployeebyJobId(tc, candidateId, erCircularId));
oSurveyEmployees = this.CreateObjects<SurveyEmployee>(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<SurveyEmployee> GetCompleteExamByCandidate(int candidateId, int erCircularId)
{
List<SurveyEmployee> oSurveyEmployees = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SurveyEmployeeDA.GetCompleteExamByCandidate(tc, candidateId, erCircularId));
oSurveyEmployees = this.CreateObjects<SurveyEmployee>(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
}
}