EchoTex_Payroll/HRM.DA/Service/UnAuthLeave/UnAuthorizeLeaveService.cs

238 lines
7.0 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
#region UnAuthorizeLeave Service
public class UnAuthorizeLeaveService : ServiceTemplate, IUnAuthorizeLeaveService
{
public UnAuthorizeLeaveService()
{
}
private void MapObject(UnAuthorizeLeave oUnAuthorizeLeave, DataReader oReader)
{
base.SetObjectID(oUnAuthorizeLeave, (oReader.GetInt32("LeaveID").Value));
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.GetInt32("CreatedBy", 0);
oUnAuthorizeLeave.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oUnAuthorizeLeave.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oUnAuthorizeLeave.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue
? oReader.GetDateTime("ModifiedDate").Value
: (DateTime?)null;
this.SetObjectState(oUnAuthorizeLeave, Ease.Core.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 List<UnAuthorizeLeave> Get(EnumStatus status, int payrollTypeID)
{
List<UnAuthorizeLeave> designations = new List<UnAuthorizeLeave>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(UnAuthorizeLeaveDA.Get(tc, status, payrollTypeID));
designations = 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
}
return designations;
}
public UnAuthorizeLeave Get(int id)
{
UnAuthorizeLeave oUnAuthorizeLeave = new UnAuthorizeLeave();
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
}
return oUnAuthorizeLeave;
}
public UnAuthorizeLeave Get(string sCode)
{
UnAuthorizeLeave oUnAuthorizeLeave = new UnAuthorizeLeave();
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
}
return oUnAuthorizeLeave;
}
public List<UnAuthorizeLeave> Get()
{
List<UnAuthorizeLeave> unAuthorizeLeaves = null;
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
}
return unAuthorizeLeaves;
}
public int Save(UnAuthorizeLeave oUnAuthorizeLeave)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oUnAuthorizeLeave.IsNew)
{
int id = tc.GenerateID("LEAVESUSPENSETYPE", "LeaveID");
base.SetObjectID(oUnAuthorizeLeave, (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(int 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
}