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

244 lines
7.4 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
public class ReviewRoleService : ServiceTemplate
{
public ReviewRoleService()
{
}
private void MapObject(ReviewRole oReviewRole, DataReader oReader)
{
base.SetObjectID(oReviewRole, oReader.GetInt32("ReviewRoleID").Value);
oReviewRole.PMPYearID = oReader.GetInt32("PMPYearID", 0);
oReviewRole.GradeID = oReader.GetInt32("GradeID", 0);
oReviewRole.KPISelf = oReader.GetBoolean("KPISelf").Value;
oReviewRole.KPISupervisor = oReader.GetBoolean("KPISupervisor").Value;
oReviewRole.BehaviourSelf = oReader.GetBoolean("BehaviourSelf").Value;
oReviewRole.BehaviourSupervisor = oReader.GetBoolean("BehaviourSupervisor").Value;
oReviewRole.TechnicalSelf = oReader.GetBoolean("TechnicalSelf").Value;
oReviewRole.TechnicalSupervisor = oReader.GetBoolean("TechnicalSupervisor").Value;
oReviewRole.ValueSelf = oReader.GetBoolean("ValueSelf").Value;
oReviewRole.ValueSupervisor = oReader.GetBoolean("ValueSupervisor").Value;
oReviewRole.DevelopmentSelf = oReader.GetBoolean("DevelopmentSelf").Value;
oReviewRole.DevelopmentSupervisor = oReader.GetBoolean("DevelopmentSupervisor").Value;
oReviewRole.PeerAppraisal = oReader.GetBoolean("PeerAppraisals").Value;
oReviewRole.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oReviewRole.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oReviewRole.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oReviewRole.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oReviewRole, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ReviewRole oReviewRole = new ReviewRole();
MapObject(oReviewRole, oReader);
return oReviewRole as T;
}
protected ReviewRole CreateObject(DataReader oReader)
{
ReviewRole oReviewRole = new ReviewRole();
MapObject(oReviewRole, oReader);
return oReviewRole;
}
#region Service Implementations
public ReviewRole GetByReviewRoleId(int id)
{
ReviewRole oReviewRole = new ReviewRole();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ReviewRoleDA.GetByReviewRoleId(tc, id));
if (oreader.Read())
{
oReviewRole = this.CreateObject<ReviewRole>(oreader);
}
oreader.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 oReviewRole;
}
public List<ReviewRole> GetByPmpYearId(int nPmpYearID)
{
List<ReviewRole> oReviewRoles = new List<ReviewRole>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ReviewRoleDA.GetByPmpYearId(tc, nPmpYearID));
oReviewRoles = this.CreateObjects<ReviewRole>(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 oReviewRoles;
}
public ReviewRole GetWithGrade(int nPmpYearID, int nGradeID)
{
ReviewRole oReviewRole = new ReviewRole();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ReviewRoleDA.GetWithGrade(tc, nPmpYearID, nGradeID));
if (oreader.Read())
{
oReviewRole = this.CreateObject<ReviewRole>(oreader);
}
oreader.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 oReviewRole;
}
public int Save(ReviewRole oReviewRole)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oReviewRole.IsNew)
{
int id = tc.GenerateID("ReviewRole", "ReviewRoleID");
base.SetObjectID(oReviewRole, id);
ReviewRoleDA.Insert(tc, oReviewRole);
}
else
{
ReviewRoleDA.Update(tc, oReviewRole);
}
tc.End();
return oReviewRole.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Save(List<ReviewRole> _reviewRoles, int nPMPYearID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ReviewRoleDA.DeleteWithYear(tc, nPMPYearID);
foreach (ReviewRole orole in _reviewRoles)
{
int id = tc.GenerateID("ReviewRole", "ReviewRoleID");
base.SetObjectID(orole, id);
ReviewRoleDA.Insert(tc, orole);
}
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 Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ReviewRoleDA.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
}
}