EchoTex_Payroll/HRM.DA/Service/PMP/QuestionnaireService.cs

175 lines
5.3 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using HRM.BO;
using HRM.DA;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using Microsoft.AspNetCore.Http;
using NPOI.SS.Formula.Functions;
using System.Collections;
namespace HRM.DA
{
public class QuestionnaireService : ServiceTemplate, IQuestionnaireService
{
public QuestionnaireService(){ }
#region Mapping Object
private void MapObject(Questionnaire oQuestionnaire, DataReader oReader)
{
base.SetObjectID(oQuestionnaire, oReader.GetInt32("QuestionnaireID").Value);
oQuestionnaire.Description = oReader.GetString("Description");
oQuestionnaire.Point = oReader.GetDouble("Point").Value;
oQuestionnaire.CompetencyID = oReader.GetInt32("COMPETENCYID").Value;
oQuestionnaire.GradeIDsInString = oReader.GetString("GradeIDs");
if(oQuestionnaire.GradeIDsInString != "")
oQuestionnaire.GradeIDs = new List<int>(Array.ConvertAll(oQuestionnaire.GradeIDsInString.Split(','), int.Parse));
oQuestionnaire.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oQuestionnaire.CreatedDate = oReader.GetDateTime("CreationDate") == null
? DateTime.Today
: oReader.GetDateTime("CreationDate").Value;
oQuestionnaire.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oQuestionnaire.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oQuestionnaire.Applicability = false;
this.SetObjectState(oQuestionnaire, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Questionnaire oQuestionnaire = new Questionnaire();
MapObject(oQuestionnaire, oReader);
return oQuestionnaire as T;
}
protected Questionnaire CreateObject(DataReader oReader)
{
Questionnaire oQuestionnaire = new Questionnaire();
MapObject(oQuestionnaire, oReader);
return oQuestionnaire;
}
#endregion
#region Save
public int Save(Questionnaire item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("Questionnaire", "QuestionnaireID");
base.SetObjectID(item, id);
QuestionnaireDA.Insert(tc, item);
}
else
{
QuestionnaireDA.Update(tc, item);
}
tc.End();
return item.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
#region Delete
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
QuestionnaireDA.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
#region Get Functions
public Questionnaire Get(int id)
{
Questionnaire oQuestionnaire = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(QuestionnaireDA.Get(tc, id));
if (oreader.Read())
{
oQuestionnaire = this.CreateObject<Questionnaire>(oreader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oQuestionnaire;
}
public List<Questionnaire> Get()
{
List<Questionnaire> Questionnaires = new List<Questionnaire>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(QuestionnaireDA.Get(tc));
Questionnaires = this.CreateObjects<Questionnaire>(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 Questionnaires;
}
#endregion
}
}