EchoTex_Payroll/HRM.DA/Service/Tax/MinTaxExceptionService.cs

162 lines
4.7 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using HRM.BO;
using Ease.Core.Utility;
using System.Collections.Generic;
using System.Data;
using Ease.Core;
using Payroll.Service;
namespace HRM.DA
{
public class MinTaxExceptionService : ServiceTemplate, IMinTaxExceptionService
{
#region Private functions and declaration
public MinTaxExceptionService()
{
}
private void MapObject(MinTaxException minTaxExceptions, DataReader oReader)
{
base.SetObjectID(minTaxExceptions, oReader.GetInt32("MinTaxExceptionID").Value);
minTaxExceptions.TaxParamID = oReader.GetInt32("TaxParamID").Value;
minTaxExceptions.EmployeeID = oReader.GetInt32("EmployeeID").Value;
minTaxExceptions.TaxExceptionType = (EnumMinimumTaxType)oReader.GetDouble("ExceptionType").Value;
minTaxExceptions.Amount = oReader.GetDouble("Amount").Value;
this.SetObjectState(minTaxExceptions, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
MinTaxException minTaxExceptions = new MinTaxException();
MapObject(minTaxExceptions, oReader);
return minTaxExceptions as T;
}
#endregion
#region Service implementation
public List<MinTaxException> Get()
{
List<MinTaxException> minTaxExceptions = new List<MinTaxException>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MinTaxExceptionDA.Get(tc));
minTaxExceptions = this.CreateObjects<MinTaxException>(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 minTaxExceptions;
}
public MinTaxException Get(int empId)
{
MinTaxException minTaxException = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MinTaxExceptionDA.Get(tc, empId));
minTaxException = this.CreateObject<MinTaxException>(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 minTaxException;
}
public void Save(List<MinTaxException> minTaxExceptions)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (MinTaxException mTaxExp in minTaxExceptions)
{
int id = tc.GenerateID("MinTaxException", "MinTaxExceptionID");
base.SetObjectID(mTaxExp, (id));
if (MinTaxExceptionDA.IsExist(tc, mTaxExp.EmployeeID, mTaxExp.TaxParamID, mTaxExp.TaxExceptionType))
{
MinTaxExceptionDA.Delete(tc, (mTaxExp.EmployeeID));
MinTaxExceptionDA.Insert(tc, mTaxExp);
}
else
{
MinTaxExceptionDA.Insert(tc, mTaxExp);
}
}
tc.End();
}
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);
MinTaxExceptionDA.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
}
}