EchoTex_Payroll/HRM.DA/Service/Claim/ClaimDisbursementService.cs

198 lines
6.8 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Payroll.BO;
using Ease.CoreV35.DataAccess;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using HRM.BO;
using Ease.Core.Utility;
namespace Payroll.Service
{
#region ClaimDisbursementService Service
public class ClaimDisbursementService : ServiceTemplate, IClaimDisbursementService
{
public ClaimDisbursementService() { }
private void MapObject(ClaimDisbursement oClaimDisbursement, DataReader oReader)
{
base.SetObjectID(oClaimDisbursement, oReader.GetInt32("ClaimDisbursementID").Value);
oClaimDisbursement.UserID = oReader.GetInt32("UserID").Value;
oClaimDisbursement.LocationID = oReader.GetInt32("LocationID").Value;
oClaimDisbursement.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value;
oClaimDisbursement.CreatedDate = oReader.GetDateTime("CREATIONDATE").Value;
oClaimDisbursement.ModifiedBy = oReader.GetString("MODIFIEDBY") == null ? null : oReader.GetInt32("MODIFIEDBY").Value;
oClaimDisbursement.ModifiedDate = oReader.GetDateTime("MODIFIEDDATE");
oClaimDisbursement.LocationCode = oReader.GetString("Code", true, null);
oClaimDisbursement.LocationName = oReader.GetString("DESCRIPTION", true, null);
oClaimDisbursement.LoginID = oReader.GetString("LOGINID", true, null);
this.SetObjectState(oClaimDisbursement, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ClaimDisbursement oClaimDisbursement = new ClaimDisbursement();
MapObject(oClaimDisbursement, oReader);
return oClaimDisbursement as T;
}
protected ClaimDisbursement CreateObject(DataReader oReader)
{
ClaimDisbursement oClaimDisbursement = new ClaimDisbursement();
MapObject(oClaimDisbursement, oReader);
return oClaimDisbursement;
}
#region Service implementation
public ClaimDisbursement Get(int id)
{
ClaimDisbursement oClaimDisbursement = new ClaimDisbursement();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ClaimDisbursementDA.Get(tc, id));
if (oreader.Read())
{
oClaimDisbursement = this.CreateObject<ClaimDisbursement>(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 oClaimDisbursement;
}
public List<ClaimDisbursement> Get()
{
#region Cache Header
List<ClaimDisbursement> oClaimDisbursementList = null;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ClaimDisbursementDA.Get(tc));
oClaimDisbursementList = this.CreateObjects<ClaimDisbursement>(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 oClaimDisbursementList;
}
public List<ClaimDisbursement> GetUserLocation()
{
#region Cache Header
List<ClaimDisbursement> oClaimDisbursementList = null;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ClaimDisbursementDA.GetUserLocation(tc));
oClaimDisbursementList = this.CreateObjects<ClaimDisbursement>(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 oClaimDisbursementList;
}
public int Save(ClaimDisbursement oClaimDisbursement)
{
TransactionContext tc = null;
int count = 0;
try
{
tc = TransactionContext.Begin(true);
DataReader dataReader = new DataReader(ClaimDisbursementDA.CheckUserLocationExist(tc, oClaimDisbursement));
while (dataReader.Read())
{
count = dataReader.GetInt32("LocationCount", 0);
}
dataReader.Close();
if(count > 0)
{
throw new Exception("This User is already Assigned to this Location");
}
if (oClaimDisbursement.IsNew)
{
int id = tc.GenerateID("ClaimDisbursementPermission", "ClaimDisbursementID");
base.SetObjectID(oClaimDisbursement, id);
ClaimDisbursementDA.Insert(tc, oClaimDisbursement);
}
else
{
ClaimDisbursementDA.Update(tc, oClaimDisbursement);
}
tc.End();
return oClaimDisbursement.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);
ClaimDisbursementDA.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
}