CEL_Payroll/Payroll.Service/UnAuthLeave/Service/UnAuthorizeLeaveService.cs

217 lines
7.2 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 UnAuthorizeLeave Service
[Serializable]
public class UnAuthorizeLeaveService : ServiceTemplate, IUnAuthorizeLeaveService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(UnAuthorizeLeave));
#endregion
public UnAuthorizeLeaveService() { }
private void MapObject(UnAuthorizeLeave oUnAuthorizeLeave, DataReader oReader)
{
base.SetObjectID(oUnAuthorizeLeave, oReader.GetID("LeaveID"));
oUnAuthorizeLeave.Name = oReader.GetString("leaveDesc");
oUnAuthorizeLeave.Code = oReader.GetString("code");
oUnAuthorizeLeave.Sequence = oReader.GetInt32("SequenceNo").Value;
oUnAuthorizeLeave.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oUnAuthorizeLeave.CreatedBy = oReader.GetID("CreatedBy");
oUnAuthorizeLeave.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oUnAuthorizeLeave.ModifiedBy = oReader.GetID("ModifiedBy");
oUnAuthorizeLeave.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oUnAuthorizeLeave, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
UnAuthorizeLeave oUnAuthorizeLeave = new UnAuthorizeLeave();
MapObject(oUnAuthorizeLeave, oReader);
return oUnAuthorizeLeave as T;
}
protected UnAuthorizeLeave CreateObject(DataReader oReader)
{
UnAuthorizeLeave oUnAuthorizeLeave = new UnAuthorizeLeave();
MapObject(oUnAuthorizeLeave, oReader);
return oUnAuthorizeLeave;
}
#region Service implementation
public UnAuthorizeLeave Get(ID id)
{
UnAuthorizeLeave oUnAuthorizeLeave = new UnAuthorizeLeave();
#region Cache Header
oUnAuthorizeLeave = _cache["Get", id] as UnAuthorizeLeave;
if (oUnAuthorizeLeave != null)
return oUnAuthorizeLeave;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(UnAuthorizeLeaveDA.Get(tc, id));
if (oreader.Read())
{
oUnAuthorizeLeave = this.CreateObject<UnAuthorizeLeave>(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(oUnAuthorizeLeave, "Get", id);
#endregion
return oUnAuthorizeLeave;
}
public UnAuthorizeLeave Get(string sCode)
{
UnAuthorizeLeave oUnAuthorizeLeave = new UnAuthorizeLeave();
#region Cache Header
oUnAuthorizeLeave = _cache["Get", sCode] as UnAuthorizeLeave;
if (oUnAuthorizeLeave != null)
return oUnAuthorizeLeave;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(UnAuthorizeLeaveDA.Get(tc, sCode));
if (oreader.Read())
{
oUnAuthorizeLeave = this.CreateObject<UnAuthorizeLeave>(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(oUnAuthorizeLeave, "Get", sCode);
#endregion
return oUnAuthorizeLeave;
}
public ObjectsTemplate<UnAuthorizeLeave> Get()
{
#region Cache Header
ObjectsTemplate<UnAuthorizeLeave> unAuthorizeLeaves = _cache["Get"] as ObjectsTemplate<UnAuthorizeLeave>;
if (unAuthorizeLeaves != null)
return unAuthorizeLeaves;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(UnAuthorizeLeaveDA.Get(tc));
unAuthorizeLeaves = this.CreateObjects<UnAuthorizeLeave>(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(unAuthorizeLeaves, "Get");
#endregion
return unAuthorizeLeaves;
}
public ID Save(UnAuthorizeLeave oUnAuthorizeLeave)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oUnAuthorizeLeave.IsNew)
{
int id = tc.GenerateID("LEAVESUSPENSETYPE", "LeaveID");
base.SetObjectID(oUnAuthorizeLeave, ID.FromInteger(id));
int seqNo = tc.GenerateID("LEAVESUSPENSETYPE", "SequenceNO");
oUnAuthorizeLeave.Sequence = seqNo;
UnAuthorizeLeaveDA.Insert(tc, oUnAuthorizeLeave);
}
else
{
UnAuthorizeLeaveDA.Update(tc, oUnAuthorizeLeave);
}
tc.End();
return oUnAuthorizeLeave.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);
UnAuthorizeLeaveDA.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
}