CEL_Payroll/Payroll.Service/HRBasic/Service/AllergyService.cs

272 lines
7.5 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
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 class AllergyService
[Serializable]
public class AllergyService : ServiceTemplate, IAllergyService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(Allergy));
#endregion
#region constructor
public AllergyService() { }
#endregion
#region Object
private void MapObject(Allergy oAllergy, DataReader oReader)
{
base.SetObjectID(oAllergy, oReader.GetID("ALLERGYID"));
oAllergy.Code = oReader.GetString("CODE");
oAllergy.Description = oReader.GetString("DESCRIPTION");
oAllergy.Sequence = oReader.GetInt32("SequenceNo").Value;
oAllergy.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oAllergy.CreatedBy = oReader.GetID("CreatedBy");
oAllergy.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oAllergy.ModifiedBy = oReader.GetID("ModifiedBy");
oAllergy.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oAllergy, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Allergy oAllergy = new Allergy();
MapObject(oAllergy, oReader);
return oAllergy as T;
}
protected Allergy CreateObject(DataReader oReader)
{
Allergy oAllergy = new Allergy();
MapObject(oAllergy, oReader);
return oAllergy;
}
#endregion
#region Service implementation
public Allergy Get(ID id)
{
Allergy oAllergy = new Allergy();
#region Cache Header
oAllergy = _cache["Get", id] as Allergy;
if (oAllergy != null)
return oAllergy;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(AllergyDA.Get(tc, id));
if (oreader.Read())
{
oAllergy = this.CreateObject<Allergy>(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(oAllergy, "Get", id);
#endregion
return oAllergy;
}
public Allergy Get(string sCode)
{
Allergy oAllergy = new Allergy();
#region Cache Header
oAllergy = _cache["Get", sCode] as Allergy;
if (oAllergy != null)
return oAllergy;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(AllergyDA.Get(tc, sCode));
if (oreader.Read())
{
oAllergy = this.CreateObject<Allergy>(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(oAllergy, "Get", sCode);
#endregion
return oAllergy;
}
public ObjectsTemplate<Allergy> Get()
{
#region Cache Header
ObjectsTemplate<Allergy> relations = _cache["Get"] as ObjectsTemplate<Allergy>;
if (relations != null)
return relations;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AllergyDA.Get(tc));
relations = this.CreateObjects<Allergy>(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(relations, "Get");
#endregion
return relations;
}
public ObjectsTemplate<Allergy> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Allergy> relations = _cache["Get"] as ObjectsTemplate<Allergy>;
if (relations != null)
return relations;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AllergyDA.Get(tc, status));
relations = this.CreateObjects<Allergy>(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(relations, "Get", status);
#endregion
return relations;
}
public ID Save(Allergy oAllergy)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oAllergy.IsNew)
{
int id = tc.GenerateID("ALLERGY", "ALLERGYID");
base.SetObjectID(oAllergy, ID.FromInteger(id));
AllergyDA.Insert(tc, oAllergy);
}
else
{
AllergyDA.Update(tc, oAllergy);
}
tc.End();
return oAllergy.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);
AllergyDA.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
}