EchoTex_Payroll/HRM.DA/Service/HRBasic/AllergyService.cs

231 lines
6.0 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using HRM.BO;
using System.Collections.Generic;
using Ease.Core.Utility;
namespace HRM.DA
{
public class AllergyService : ServiceTemplate, IAllergyService
{
#region constructor
public AllergyService()
{
}
#endregion
#region Object
private void MapObject(Allergy oAllergy, DataReader oReader)
{
base.SetObjectID(oAllergy, oReader.GetInt32("ALLERGYID").Value);
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.GetInt32("CreatedBy", 0);
oAllergy.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oAllergy.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oAllergy.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oAllergy, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Allergy oAllergy = new Allergy();
MapObject(oAllergy, oReader);
return oAllergy as T;
}
#endregion
#region Service implementation
public Allergy Get(int id)
{
Allergy oAllergy = null;
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
}
return oAllergy;
}
public Allergy Get(string sCode)
{
Allergy oAllergy = null;
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
}
return oAllergy;
}
public List<Allergy> Get()
{
List<Allergy> relations = new List<Allergy>();
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
}
return relations;
}
public List<Allergy> Get(EnumStatus status)
{
List<Allergy> relations = new List<Allergy>();
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
}
return relations;
}
public int Save(Allergy oAllergy)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oAllergy.IsNew)
{
int id = tc.GenerateID("ALLERGY", "ALLERGYID");
base.SetObjectID(oAllergy, 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(int 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
}
}