CEL_Payroll/Payroll.Service/HRBasic/Service/OtherTalentService.cs

274 lines
7.9 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 OtherTalentService
[Serializable]
public class OtherTalentService : ServiceTemplate, IOtherTalentService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(OtherTalent));
#endregion
#region constructor
public OtherTalentService()
{ }
#endregion
#region object
private void MapObject(OtherTalent oOtherTalent, DataReader oReader)
{
base.SetObjectID(oOtherTalent, oReader.GetID("OTHERTALENTID"));
oOtherTalent.Code = oReader.GetString("CODE");
oOtherTalent.Description = oReader.GetString("DESCRIPTION");
oOtherTalent.Sequence = oReader.GetInt32("SequenceNo").Value;
oOtherTalent.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oOtherTalent.CreatedBy = oReader.GetID("CreatedBy");
oOtherTalent.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oOtherTalent.ModifiedBy = oReader.GetID("ModifiedBy");
oOtherTalent.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oOtherTalent, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
OtherTalent oOtherTalent = new OtherTalent();
MapObject(oOtherTalent, oReader);
return oOtherTalent as T;
}
protected OtherTalent CreateObject(DataReader oReader)
{
OtherTalent oOtherTalent = new OtherTalent();
MapObject(oOtherTalent, oReader);
return oOtherTalent;
}
#endregion
#region service implementation
public OtherTalent Get(ID id)
{
OtherTalent oOtherTalent = new OtherTalent();
#region cache header
oOtherTalent = _cache["Get", id] as OtherTalent;
if (oOtherTalent != null)
return oOtherTalent;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OtherTalentDA.Get(tc, id));
if (oreader.Read())
{
oOtherTalent = this.CreateObject<OtherTalent>(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(oOtherTalent, "Get", id);
#endregion
return oOtherTalent;
}
public OtherTalent Get(string sCode)
{
OtherTalent oOtherTalent = new OtherTalent();
#region cache header
oOtherTalent = _cache["Get", sCode] as OtherTalent;
if (oOtherTalent != null)
return oOtherTalent;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OtherTalentDA.Get(tc, sCode));
if (oreader.Read())
{
oOtherTalent = this.CreateObject<OtherTalent>(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(oOtherTalent, "Get", sCode);
#endregion
return oOtherTalent;
}
public ObjectsTemplate<OtherTalent> Get()
{
#region Cache Header
ObjectsTemplate<OtherTalent> otherTalents = _cache["Get"] as ObjectsTemplate<OtherTalent>;
if (otherTalents != null)
return otherTalents;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OtherTalentDA.Get(tc));
otherTalents = this.CreateObjects<OtherTalent>(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(otherTalents, "Get");
#endregion
return otherTalents;
}
public ObjectsTemplate<OtherTalent> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<OtherTalent> otherTalents = _cache["Get"] as ObjectsTemplate<OtherTalent>;
if (otherTalents != null)
return otherTalents;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OtherTalentDA.Get(tc, status));
otherTalents = this.CreateObjects<OtherTalent>(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(otherTalents, "Get", status);
#endregion
return otherTalents;
}
public ID Save(OtherTalent oOtherTalent)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oOtherTalent.IsNew)
{
int id = tc.GenerateID("OTHERTALENT", "OTHERTALENTID");
base.SetObjectID(oOtherTalent, ID.FromInteger(id));
OtherTalentDA.Insert(tc, oOtherTalent);
}
else
{
OtherTalentDA.Update(tc, oOtherTalent);
}
tc.End();
return oOtherTalent.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);
OtherTalentDA.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
}