CEL_Payroll/Payroll.Service/HRBasic/Service/TrainingScheduleStatusService.cs

232 lines
7.3 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 Class TrainingScheduleStatus Service
[Serializable]
public class TrainingScheduleStatusService : ServiceTemplate, ITrainingScheduleStatusService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(TrainingScheduleStatus));
#endregion
#region Object
private void MapObject(TrainingScheduleStatus oTrainingScheduleStatus, DataReader oReader)
{
base.SetObjectID(oTrainingScheduleStatus, oReader.GetID("TRAININGSCHEDULESTATUSID"));
oTrainingScheduleStatus.Name = oReader.GetString("Name");
oTrainingScheduleStatus.Sequence = oReader.GetInt32("SEQUENCENO").Value;
oTrainingScheduleStatus.Status = (EnumStatus)oReader.GetInt32("STATUS").Value;
oTrainingScheduleStatus.CreatedBy = oReader.GetID("CREATEDBY");
oTrainingScheduleStatus.CreatedDate = oReader.GetDateTime("CREATIONDATE").Value;
oTrainingScheduleStatus.ModifiedBy = oReader.GetID("MODIFIEDBY");
oTrainingScheduleStatus.ModifiedDate = oReader.GetDateTime("MODIFIEDDATE");
this.SetObjectState(oTrainingScheduleStatus, Ease.CoreV35.ObjectState.Saved);
}
#region Overrides of ServiceTemplate
protected override T CreateObject<T>(DataReader dr)
{
TrainingScheduleStatus oTrainingScheduleStatus = new TrainingScheduleStatus();
MapObject(oTrainingScheduleStatus, dr);
return oTrainingScheduleStatus as T;
}
#endregion
protected TrainingScheduleStatus CreateObject(DataReader oReader)
{
TrainingScheduleStatus oTrainingScheduleStatus = new TrainingScheduleStatus();
MapObject(oTrainingScheduleStatus, oReader);
return oTrainingScheduleStatus;
}
#endregion
#region Implementation of ITrainingScheduleStatusService
public void Delete(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
TrainingScStatusDA.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
}
}
public ID Save(TrainingScheduleStatus oTrainingScheduleStatus)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oTrainingScheduleStatus.IsNew)
{
int id = tc.GenerateID("TRAININGSCHEDULESTATUS", "TRAININGSCHEDULESTATUSID");
base.SetObjectID(oTrainingScheduleStatus, ID.FromInteger(id));
TrainingScStatusDA.Insert(tc, oTrainingScheduleStatus);
}
else
{
TrainingScStatusDA.Update(tc, oTrainingScheduleStatus);
}
tc.End();
return oTrainingScheduleStatus.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public ObjectsTemplate<TrainingScheduleStatus> Get()
{
#region Cache Header
ObjectsTemplate<TrainingScheduleStatus> trainingStatusses = _cache["Get"] as ObjectsTemplate<TrainingScheduleStatus>;
if (trainingStatusses != null)
return trainingStatusses;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TrainingScStatusDA.Get(tc));
trainingStatusses = this.CreateObjects<TrainingScheduleStatus>(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(trainingStatusses, "Get");
#endregion
return trainingStatusses;
}
public TrainingScheduleStatus Get(ID id)
{
TrainingScheduleStatus oTrainingScheduleStatus = new TrainingScheduleStatus();
#region Cache Header
oTrainingScheduleStatus = _cache["Get", id] as TrainingScheduleStatus;
if (oTrainingScheduleStatus != null)
return oTrainingScheduleStatus;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScStatusDA.Get(tc, id));
if (oreader.Read())
{
oTrainingScheduleStatus = this.CreateObject<TrainingScheduleStatus>(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
}
#region Cache Footer
_cache.Add(oTrainingScheduleStatus, "Get", id);
#endregion
return oTrainingScheduleStatus;
}
public ObjectsTemplate<TrainingScheduleStatus> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<TrainingScheduleStatus> trainingScheduleStatuses = _cache["Get"] as ObjectsTemplate<TrainingScheduleStatus>;
if (trainingScheduleStatuses != null)
return trainingScheduleStatuses;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TrainingScStatusDA.Get(tc, status));
trainingScheduleStatuses = this.CreateObjects<TrainingScheduleStatus>(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(trainingScheduleStatuses, "Get", status);
#endregion
return trainingScheduleStatuses;
}
#endregion
}
#endregion
}