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

362 lines
10 KiB
C#

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 TrainingScheduleAttnService : ServiceTemplate, ITrainingScheduleAttnService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(TrainingScheduleAttn));
private void MapObject(TrainingScheduleAttn oTrainingScheduleAttn, DataReader oReader)
{
base.SetObjectID(oTrainingScheduleAttn, oReader.GetID("TSAttnID"));
oTrainingScheduleAttn.TrainingScheduleID = oReader.GetID("TrainingScheduleID");
oTrainingScheduleAttn.TSDateID = oReader.GetID("TSDateID");
oTrainingScheduleAttn.EmployeeID = oReader.GetID("EmployeeID");
this.SetObjectState(oTrainingScheduleAttn, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
TrainingScheduleAttn oTrainingScheduleAttng = new TrainingScheduleAttn();
MapObject(oTrainingScheduleAttng, oReader);
return oTrainingScheduleAttng as T;
}
#endregion
#region Implementation of ITrainingScheduleAttnService
#region Get TrainingScheduleAttn
public TrainingScheduleAttn Get(ID trainingScheduleAttnID)
{
TrainingScheduleAttn otrainingScheduleAttn = null;
#region CacheHeader
otrainingScheduleAttn = (TrainingScheduleAttn)_cache["Get", trainingScheduleAttnID];
if (otrainingScheduleAttn != null)
return otrainingScheduleAttn;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScheduleAttnDA.Get(tc, trainingScheduleAttnID.Integer));
oreader.Read();
otrainingScheduleAttn = CreateObject<TrainingScheduleAttn>(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(otrainingScheduleAttn, "Get", trainingScheduleAttnID);
#endregion
return otrainingScheduleAttn;
}
#endregion
#region Get ObjectsTemplate<TrainingScheduleAttn>
public ObjectsTemplate<TrainingScheduleAttn> Get()
{
ObjectsTemplate<TrainingScheduleAttn> trainingScheduleAttns;
#region CacheHeader
trainingScheduleAttns = (ObjectsTemplate<TrainingScheduleAttn>)_cache["Get"];
if (trainingScheduleAttns != null)
return trainingScheduleAttns;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScheduleAttnDA.Get(tc));
trainingScheduleAttns = CreateObjects<TrainingScheduleAttn>(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(trainingScheduleAttns, "Get");
#endregion
return trainingScheduleAttns;
}
public ObjectsTemplate<TrainingScheduleAttn> GetByTrainingScheduleID(ID trainingScheduleID)
{
ObjectsTemplate<TrainingScheduleAttn> trainingScheduleAttns;
#region CacheHeader
trainingScheduleAttns = (ObjectsTemplate<TrainingScheduleAttn>)_cache["Get"];
if (trainingScheduleAttns != null)
return trainingScheduleAttns;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScheduleAttnDA.GetByTrainingScheduleID(tc, trainingScheduleID));
trainingScheduleAttns = CreateObjects<TrainingScheduleAttn>(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(trainingScheduleAttns, "Get");
#endregion
return trainingScheduleAttns;
}
public ObjectsTemplate<TrainingScheduleAttn> GetByTrainingScheduleDateID(ID trainingScheduleDateID)
{
ObjectsTemplate<TrainingScheduleAttn> trainingScheduleAttns;
#region CacheHeader
trainingScheduleAttns = (ObjectsTemplate<TrainingScheduleAttn>)_cache["Get"];
if (trainingScheduleAttns != null)
return trainingScheduleAttns;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScheduleAttnDA.GetByTrainingScheduleDateID(tc, trainingScheduleDateID));
trainingScheduleAttns = CreateObjects<TrainingScheduleAttn>(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(trainingScheduleAttns, "Get");
#endregion
return trainingScheduleAttns;
}
#endregion
#region Save TrainingScheduleAttn
public ID Save(TrainingScheduleAttn oTrainingScheduleAttn)
{
try
{
TransactionContext tc = null;
try
{
#region Saving data
tc = TransactionContext.Begin(true);
if (oTrainingScheduleAttn.IsNew)
{
int newID = tc.GenerateID("TrainingScheduleAttn", "TSAttnID");
base.SetObjectID(oTrainingScheduleAttn, ID.FromInteger(newID));
TrainingScheduleAttnDA.Insert(tc, oTrainingScheduleAttn);
}
else
TrainingScheduleAttnDA.Update(tc, oTrainingScheduleAttn);
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 oTrainingScheduleAttn.ID;
}
public ID Save(TransactionContext tc, TrainingScheduleAttn oTrainingScheduleAttn)
{
try
{
try
{
#region Saving data
if (oTrainingScheduleAttn.IsNew)
{
int newID = tc.GenerateID("TrainingScheduleAttn", "TSAttnID");
base.SetObjectID(oTrainingScheduleAttn, ID.FromInteger(newID));
TrainingScheduleAttnDA.Insert(tc, oTrainingScheduleAttn);
}
else
TrainingScheduleAttnDA.Update(tc, oTrainingScheduleAttn);
#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 oTrainingScheduleAttn.ID;
}
#endregion
#region Delete
public void Delete(ID id)
{
try
{
TransactionContext tc = null;
try
{
#region Deleting data
tc = TransactionContext.Begin(true);
TrainingScheduleAttnDA.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 DoesTrainingScheduleAttnExists(ID trainingScheduleDateID)
{
try
{
TransactionContext tc = null;
tc = TransactionContext.Begin();
bool result = false;
result = TrainingScheduleAttnDA.DoesTrainingScheduleAttnExists(tc,trainingScheduleDateID);
tc.End();
return result;
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
}
#endregion
}
#endregion
}