EchoTex_Payroll/HRM.DA/Service/Succession/SuccessionPlanningService.cs

203 lines
6.7 KiB
C#
Raw Permalink 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;
namespace HRM.DA
{
public class SuccessionPlanningService : ServiceTemplate, ISuccessionPlanningService
{
public SuccessionPlanningService()
{
}
private void MapObject(SuccessionPlanning oSuccessionPlanning, DataReader oReader)
{
base.SetObjectID(oSuccessionPlanning, oReader.GetInt32("SuccessionPlanningID").Value);
oSuccessionPlanning.PlanByUserID = oReader.GetInt32("PlanByUserID", 0);
oSuccessionPlanning.PlanByEmployeeID = oReader.GetInt32("PlanByEmployeeID",0);
oSuccessionPlanning.EntryDate = oReader.GetDateTime("EntryDate").Value;
oSuccessionPlanning.SuccessionRoleID = oReader.GetInt32("SuccessionRoleID").Value;
oSuccessionPlanning.PlanDate = oReader.GetDateTime("PlanDate",DateTime.MinValue);
oSuccessionPlanning.EmployeeID = oReader.GetInt32("EmployeeID").Value;
oSuccessionPlanning.EmpDesignationID = oReader.GetInt32("EmpDesignationID").Value;
oSuccessionPlanning.SuccessionType = (EnumSuccessorType)oReader.GetInt32("SuccessionType").Value;
oSuccessionPlanning.SuccessorOneID = oReader.GetInt32("SuccessorOneID", 0);
oSuccessionPlanning.SuccessorOneReadiness = (EnumSuccessorReadiness)oReader.GetInt32("SuccessorOneReadiness", 0);
oSuccessionPlanning.SuccessorTwoID = oReader.GetInt32("SuccessorTwoID", 0);
oSuccessionPlanning.SuccessorTwoReadiness = (EnumSuccessorReadiness)oReader.GetInt32("SuccessorTwoReadiness", 0);
oSuccessionPlanning.Remarks = oReader.GetString("Remarks", null);
oSuccessionPlanning.OursideSuccessor = oReader.GetString("OursideSuccessor", null);
oSuccessionPlanning.PlanningYear = oReader.GetDateTime("PlanningYear").Value;
oSuccessionPlanning.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oSuccessionPlanning.CreatedDate = oReader.GetDateTime("CreationDate") == null
? DateTime.Today
: oReader.GetDateTime("CreationDate").Value;
oSuccessionPlanning.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oSuccessionPlanning.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oSuccessionPlanning, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
SuccessionPlanning oSuccessionPlanning = new SuccessionPlanning();
MapObject(oSuccessionPlanning, oReader);
return oSuccessionPlanning as T;
}
#region Service implementation
public SuccessionPlanning Get(TransactionContext tc, int id)
{
SuccessionPlanning oSuccessionPlanning = null;
try
{
DataReader oreader = new DataReader(SuccessionPlanningDA.Get(tc, id));
if (oreader.Read())
{
oSuccessionPlanning = this.CreateObject<SuccessionPlanning>(oreader);
}
oreader.Close();
}
catch (Exception e)
{
#region Handle Exception
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oSuccessionPlanning;
}
public SuccessionPlanning Get(int id)
{
SuccessionPlanning oSuccessionPlanning = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(SuccessionPlanningDA.Get(tc, id));
if (oreader.Read())
{
oSuccessionPlanning = this.CreateObject<SuccessionPlanning>(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 oSuccessionPlanning;
}
public List<SuccessionPlanning> Get()
{
List<SuccessionPlanning> roles = new List<SuccessionPlanning>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SuccessionPlanningDA.Get(tc));
roles = this.CreateObjects<SuccessionPlanning>(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 roles;
}
public int Save(SuccessionPlanning oSuccessionPlanning)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oSuccessionPlanning.IsNew)
{
int id = tc.GenerateID("SuccessionPlanning", "SuccessionPlanningID");
base.SetObjectID(oSuccessionPlanning, id);
SuccessionPlanningDA.Insert(tc, oSuccessionPlanning);
}
else
{
SuccessionPlanningDA.Update(tc, oSuccessionPlanning);
}
tc.End();
return oSuccessionPlanning.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
SuccessionPlanningDA.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
}
}
}
}