CEL_Payroll/Payroll.Service/TrainingS/Service/TrainingCostHeadService.cs

243 lines
6.8 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 TrainingCostHead Service
[Serializable]
class TrainingCostHeadService : ServiceTemplate, ITrainingCostHeadService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(TrainingCostHead));
private void MapObject(TrainingCostHead oTrainingCostHead, DataReader oReader)
{
base.SetObjectID(oTrainingCostHead, oReader.GetID("TrainingCostHeadID"));
oTrainingCostHead.Code = oReader.GetString("Code");
oTrainingCostHead.Name = oReader.GetString("Name");
//oTrainingCostHead. = (EnumStatus)oReader.GetInt32("Status").Value;
oTrainingCostHead.CreatedBy = oReader.GetID("CreatedBy");
oTrainingCostHead.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue?oReader.GetDateTime("CreatedDate").Value:DateTime.Today;
oTrainingCostHead.ModifiedBy = oReader.GetID("ModifiedBy");
oTrainingCostHead.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oTrainingCostHead, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
TrainingCostHead oTrainingCostHead = new TrainingCostHead();
MapObject(oTrainingCostHead, oReader);
return oTrainingCostHead as T;
}
#endregion
#region Implementation of ITrainingCostHeadService
#region Get TrainingCostHead
public TrainingCostHead Get(ID TrainingCostHeadID)
{
TrainingCostHead oTrainingCostHead = null;
#region CacheHeader
oTrainingCostHead = (TrainingCostHead)_cache["Get", TrainingCostHeadID];
if (oTrainingCostHead != null)
return oTrainingCostHead;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingCostHeadDA.Get(tc, TrainingCostHeadID.Integer));
oreader.Read();
oTrainingCostHead = CreateObject<TrainingCostHead>(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(oTrainingCostHead, "Get", TrainingCostHeadID);
#endregion
return oTrainingCostHead;
}
#endregion
#region Get TrainingCostHeads
public ObjectsTemplate<TrainingCostHead> Get()
{
ObjectsTemplate<TrainingCostHead> oTrainingCostHeads;
#region CacheHeader
oTrainingCostHeads = (ObjectsTemplate<TrainingCostHead>)_cache["Get"];
if (oTrainingCostHeads != null)
return oTrainingCostHeads;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingCostHeadDA.Get(tc));
oTrainingCostHeads = CreateObjects<TrainingCostHead>(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(oTrainingCostHeads, "Get");
#endregion
return oTrainingCostHeads;
}
#endregion
#region Save TrainingCostHead
public ID Save(TrainingCostHead oTrainingCostHead)
{
try
{
TransactionContext tc = null;
try
{
#region Saving data
tc = TransactionContext.Begin(true);
#region Checking Duplicate TrainingCostHead Code
bool result = false;
result = TrainingCostHeadDA.IsExists("TrainingCostHead", "Code", oTrainingCostHead.Code, tc);
if (result & oTrainingCostHead.IsNew)
{
throw new ServiceException("Duplicate code is not allowed.");
}
#endregion
if (oTrainingCostHead.IsNew)
{
int newID = tc.GenerateID("TrainingCostHead", "TrainingCostHeadID");
base.SetObjectID(oTrainingCostHead, ID.FromInteger(newID));
TrainingCostHeadDA.Insert(tc, oTrainingCostHead);
}
else
TrainingCostHeadDA.Update(tc, oTrainingCostHead);
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 oTrainingCostHead.ID;
}
#endregion
#region Delete Trainng
public void Delete(ID TrainingCostHeadID)
{
try
{
TransactionContext tc = null;
try
{
#region Deleting data
tc = TransactionContext.Begin(true);
TrainingCostHeadDA.Delete(tc, TrainingCostHeadID.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
#endregion
}
#endregion
}