CEL_Payroll/Payroll.Service/HRBasic/Service/OccupationService.cs
2024-09-17 14:30:13 +06:00

269 lines
7.8 KiB
C#

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