CEL_Payroll/Payroll.Service/TrainingS/Service/TrainingDepartmentService.cs

321 lines
9.1 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using Ease.CoreV35.Caching;
using Ease.CoreV35.DataAccess;
using Ease.CoreV35.Model;
using Payroll.BO;
namespace Payroll.Service
{
#region Training Service
[Serializable]
class TrainingDepartmentService : ServiceTemplate, ITrainingDepartmentService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(TrainingDepartment));
private void MapObject(TrainingDepartment oTrainingDepartment, DataReader oReader)
{
base.SetObjectID(oTrainingDepartment, oReader.GetID("TrainDepartmentID"));
oTrainingDepartment.TrainingNeedAnalysisID = oReader.GetID("TrainingNeedAnalysisID");
oTrainingDepartment.DepartmentID = oReader.GetID("DepartmentID");
oTrainingDepartment.Remarks = oReader.GetString("Remarks");
this.SetObjectState(oTrainingDepartment, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
TrainingDepartment oTrainingDepartmentg = new TrainingDepartment();
MapObject(oTrainingDepartmentg, oReader);
return oTrainingDepartmentg as T;
}
#endregion
#region Implementation of ITrainingDepartmentService
#region Get TrainingDepartment
public TrainingDepartment Get(ID TrainingDepartmentID)
{
TrainingDepartment oTrainingDepartment = null;
#region CacheHeader
oTrainingDepartment = (TrainingDepartment)_cache["Get", TrainingDepartmentID];
if (oTrainingDepartment != null)
return oTrainingDepartment;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingDepartmentDA.Get(tc, TrainingDepartmentID.Integer));
oreader.Read();
oTrainingDepartment = CreateObject<TrainingDepartment>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
#region CacheFooter
_cache.Add(oTrainingDepartment, "Get", TrainingDepartmentID);
#endregion
return oTrainingDepartment;
}
#endregion
#region Get ObjectsTemplate<TrainingDepartment>
public ObjectsTemplate<TrainingDepartment> Get()
{
ObjectsTemplate<TrainingDepartment> TrainingDepartments;
#region CacheHeader
TrainingDepartments = (ObjectsTemplate<TrainingDepartment>)_cache["Get"];
if (TrainingDepartments != null)
return TrainingDepartments;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingDepartmentDA.Get(tc));
TrainingDepartments = CreateObjects<TrainingDepartment>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
#region CacheFooter
_cache.Add(TrainingDepartments, "Get");
#endregion
return TrainingDepartments;
}
public ObjectsTemplate<TrainingDepartment> GetByTrainingNeedAnalysisID(ID TrainingNeedAnalysisID)
{
ObjectsTemplate<TrainingDepartment> TrainingDepartments;
#region CacheHeader
TrainingDepartments = (ObjectsTemplate<TrainingDepartment>)_cache["Get"];
if (TrainingDepartments != null)
return TrainingDepartments;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingDepartmentDA.GetByTrainingNeedAnalysisID(tc, TrainingNeedAnalysisID));
TrainingDepartments = CreateObjects<TrainingDepartment>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
#region CacheFooter
_cache.Add(TrainingDepartments, "Get");
#endregion
return TrainingDepartments;
}
#endregion
#region Save TrainingDepartment
public ID Save(TrainingDepartment oTrainingDepartment)
{
try
{
TransactionContext tc = null;
try
{
#region Saving data
tc = TransactionContext.Begin(true);
if (oTrainingDepartment.IsNew)
{
int newID = tc.GenerateID("TrainingDepartment", "TrainDepartmentID");
base.SetObjectID(oTrainingDepartment, ID.FromInteger(newID));
TrainingDepartmentDA.Insert(tc, oTrainingDepartment);
}
else
TrainingDepartmentDA.Update(tc, oTrainingDepartment);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
//throw new ServiceException(e.Message, e);
throw new Exception(e.Message, e);
}
return oTrainingDepartment.ID;
}
public ID Save(TransactionContext tc, TrainingDepartment oTrainingDepartment)
{
try
{
try
{
#region Saving data
if (oTrainingDepartment.IsNew)
{
int newID = tc.GenerateID("TrainingDepartment", "TrainDepartmentID");
base.SetObjectID(oTrainingDepartment, ID.FromInteger(newID));
TrainingDepartmentDA.Insert(tc, oTrainingDepartment);
}
else
TrainingDepartmentDA.Update(tc, oTrainingDepartment);
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
//throw new ServiceException(e.Message, e);
throw new Exception(e.Message, e);
}
return oTrainingDepartment.ID;
}
#endregion
#region Delete
public void Delete(ID id)
{
try
{
TransactionContext tc = null;
try
{
#region Deleting data
tc = TransactionContext.Begin(true);
TrainingDepartmentDA.Delete(tc, id.Integer);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
throw new ServiceException(e.Message, e);
}
}
#endregion
public bool DoesTrainingDepartmentExists(ID TrainingDepartmentID)
{
try
{
TransactionContext tc = null;
tc = TransactionContext.Begin();
bool result = false;
result = TrainingDepartmentDA.DoesTrainingDepartmentExists(tc, TrainingDepartmentID);
tc.End();
return result;
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
}
#endregion
}
#endregion
}