CEL_Payroll/Payroll.Service/Attendence/Service/OutsideDutyService.cs

213 lines
6.7 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.Model;
using Payroll.BO;
using Ease.CoreV35.Caching;
using Ease.CoreV35.DataAccess;
using Payroll.Service.Attendence.DA;
using Payroll.BO;
namespace Payroll.Service.Attendence.Service
{
#region OutsideDuty Service
[Serializable]
public class OutsideDutyService : ServiceTemplate, IOutsideDutyService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(OutsideDuty));
#endregion
public OutsideDutyService() { }
private void MapObject(OutsideDuty oOutsideDuty, DataReader oReader)
{
base.SetObjectID(oOutsideDuty, oReader.GetID("OutsideDutyID"));
oOutsideDuty.Name = oReader.GetString("Name");
oOutsideDuty.Sequence = oReader.GetInt32("SequenceNo").Value;
oOutsideDuty.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oOutsideDuty.CreatedBy = oReader.GetID("CreatedBy");
oOutsideDuty.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oOutsideDuty.ModifiedBy = oReader.GetID("ModifiedBy");
oOutsideDuty.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oOutsideDuty, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
OutsideDuty oOutsideDuty = new OutsideDuty();
MapObject(oOutsideDuty, oReader);
return oOutsideDuty as T;
}
protected OutsideDuty CreateObject(DataReader oReader)
{
OutsideDuty oOutsideDuty = new OutsideDuty();
MapObject(oOutsideDuty, oReader);
return oOutsideDuty;
}
#region Service implementation
public OutsideDuty Get(ID id)
{
OutsideDuty oOutsideDuty = new OutsideDuty();
#region Cache Header
oOutsideDuty = _cache["Get", id] as OutsideDuty;
if (oOutsideDuty != null)
return oOutsideDuty;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OutsideDutyDA.Get(tc, id));
if (oreader.Read())
{
oOutsideDuty = this.CreateObject<OutsideDuty>(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(oOutsideDuty, "Get", id);
#endregion
return oOutsideDuty;
}
public ObjectsTemplate<OutsideDuty> Get()
{
#region Cache Header
ObjectsTemplate<OutsideDuty> outsideDutys = _cache["Get"] as ObjectsTemplate<OutsideDuty>;
if (outsideDutys != null)
return outsideDutys;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OutsideDutyDA.Get(tc));
outsideDutys = this.CreateObjects<OutsideDuty>(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(outsideDutys, "Get");
#endregion
return outsideDutys;
}
public ObjectsTemplate<OutsideDuty> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<OutsideDuty> oOutsideDuties = _cache["Get"] as ObjectsTemplate<OutsideDuty>;
if (oOutsideDuties != null)
return oOutsideDuties;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OutsideDutyDA.Get(tc, status));
oOutsideDuties = this.CreateObjects<OutsideDuty>(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(oOutsideDuties, "Get", status);
#endregion
return oOutsideDuties;
}
public ID Save(OutsideDuty oOutsideDuty)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oOutsideDuty.IsNew)
{
int id = tc.GenerateID("OutsideDuty", "OutsideDutyID");
base.SetObjectID(oOutsideDuty, ID.FromInteger(id));
int seqNo = tc.GenerateID("OutsideDuty", "SequenceNO");
oOutsideDuty.Sequence = seqNo;
OutsideDutyDA.Insert(tc, oOutsideDuty);
}
else
{
OutsideDutyDA.Update(tc, oOutsideDuty);
}
tc.End();
return oOutsideDuty.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);
OutsideDutyDA.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
}