CEL_Payroll/Payroll.Service/EmpRequisition/Service/CreatedRequisitionService.cs
2024-09-17 14:30:13 +06:00

135 lines
4.3 KiB
C#

using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
#region CreatedRequisition Service
[Serializable]
public class CreatedRequisitionService : ServiceTemplate, ICreatedRequisitionService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(CreatedRequisition));
#endregion
public CreatedRequisitionService() { }
private void MapObject(CreatedRequisition oCreatedRequisition, DataReader oReader)
{
base.SetObjectID(oCreatedRequisition, oReader.GetID("CreatedRequisitionID"));
oCreatedRequisition.EmpRequisitionID = oReader.GetID("RecruitementProcessID");
oCreatedRequisition.EmpRequisitionID = oReader.GetID("EmpRequisitionID");
this.SetObjectState(oCreatedRequisition, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
CreatedRequisition oCreatedRequisition = new CreatedRequisition();
MapObject(oCreatedRequisition, oReader);
return oCreatedRequisition as T;
}
protected CreatedRequisition CreateObject(DataReader oReader)
{
CreatedRequisition oCreatedRequisition = new CreatedRequisition();
MapObject(oCreatedRequisition, oReader);
return oCreatedRequisition;
}
#region Service implementation
public ObjectsTemplate<CreatedRequisition> Get()
{
#region Cache Header
ObjectsTemplate<CreatedRequisition> CreatedRequisitions = _cache["Get"] as ObjectsTemplate<CreatedRequisition>;
if (CreatedRequisitions != null)
return CreatedRequisitions;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CreatedRequisitionDA.Get(tc));
CreatedRequisitions = this.CreateObjects<CreatedRequisition>(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
}
#region Cache Footer
_cache.Add(CreatedRequisitions, "Get");
#endregion
return CreatedRequisitions;
}
public ID Save(CreatedRequisition oCreatedRequisition)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oCreatedRequisition.IsNew)
{
int id = tc.GenerateID("CreatedRequisition", "CreatedRequisitionID");
base.SetObjectID(oCreatedRequisition, ID.FromInteger(id));
CreatedRequisitionDA.Insert(tc, oCreatedRequisition);
}
tc.End();
return oCreatedRequisition.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Delete(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
CreatedRequisitionDA.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
}
#endregion
}