CEL_Payroll/Payroll.Service/Tax/Service/EmployeeTaxInvestmentService.cs

352 lines
11 KiB
C#
Raw 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 EmployeeTaxInvestment Service
[Serializable]
public class EmployeeTaxInvestmentService : ServiceTemplate, IEmployeeTaxInvestmentService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(EmployeeTaxInvestment));
#endregion
public EmployeeTaxInvestmentService() { }
private void MapObject(EmployeeTaxInvestment oEmployeeTaxInvestment, DataReader oReader)
{
base.SetObjectID(oEmployeeTaxInvestment, oReader.GetID("InvestmentID"));
oEmployeeTaxInvestment.EmployeeID = oReader.GetID("employeeID");
oEmployeeTaxInvestment.Amount = oReader.GetDouble("amount").Value;
oEmployeeTaxInvestment.TaxparameterId = oReader.GetID("taxParamID");
oEmployeeTaxInvestment.TypeID = oReader.GetID("typeID");
oEmployeeTaxInvestment.Sequence = oReader.GetInt32("SequenceNO").Value;
oEmployeeTaxInvestment.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oEmployeeTaxInvestment.CreatedBy = oReader.GetID("CreatedBy");
oEmployeeTaxInvestment.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oEmployeeTaxInvestment.ModifiedBy = oReader.GetID("ModifiedBy");
oEmployeeTaxInvestment.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue ? oReader.GetDateTime("ModifiedDate") : (DateTime?)null ;
this.SetObjectState(oEmployeeTaxInvestment, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
EmployeeTaxInvestment oEmployeeTaxInvestment = new EmployeeTaxInvestment();
MapObject(oEmployeeTaxInvestment, oReader);
return oEmployeeTaxInvestment as T;
}
protected EmployeeTaxInvestment CreateObject(DataReader oReader)
{
EmployeeTaxInvestment oEmployeeTaxInvestment = new EmployeeTaxInvestment();
MapObject(oEmployeeTaxInvestment, oReader);
return oEmployeeTaxInvestment;
}
#region Service implementation
public EmployeeTaxInvestment Get(ID id)
{
EmployeeTaxInvestment oEmployeeTaxInvestment = new EmployeeTaxInvestment();
#region Cache Header
oEmployeeTaxInvestment = _cache["Get", id] as EmployeeTaxInvestment;
if (oEmployeeTaxInvestment != null)
return oEmployeeTaxInvestment;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeTaxInvestmentDA.Get(tc, id));
if (oreader.Read())
{
oEmployeeTaxInvestment = this.CreateObject<EmployeeTaxInvestment>(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(oEmployeeTaxInvestment, "Get", id);
#endregion
return oEmployeeTaxInvestment;
}
public ObjectsTemplate<EmployeeTaxInvestment> Get()
{
#region Cache Header
ObjectsTemplate<EmployeeTaxInvestment> employeeTaxInvestments = _cache["Get"] as ObjectsTemplate<EmployeeTaxInvestment>;
if (employeeTaxInvestments != null)
return employeeTaxInvestments;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeTaxInvestmentDA.Get(tc));
employeeTaxInvestments = this.CreateObjects<EmployeeTaxInvestment>(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(employeeTaxInvestments, "Get");
#endregion
return employeeTaxInvestments;
}
public ObjectsTemplate<EmployeeTaxInvestment> GetAllUsersInfo(int taxParamID)
{
ObjectsTemplate<EmployeeTaxInvestment> employeeTaxInvestments = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeTaxInvestmentDA.GetAllUsersInfo(tc, taxParamID));
employeeTaxInvestments = this.CreateObjects<EmployeeTaxInvestment>(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 employeeTaxInvestments;
}
public ObjectsTemplate<EmployeeTaxInvestment> GetSingleEmpsInfo(ID id)
{
ObjectsTemplate<EmployeeTaxInvestment> employeeTaxInvestments = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeTaxInvestmentDA.GetSingleEmpsInfo(tc, id));
employeeTaxInvestments = this.CreateObjects<EmployeeTaxInvestment>(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 employeeTaxInvestments;
}
public double GetAmount(ID TaxParamID, ID EmployeeID)
{
double InvestAmount = 0.0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
InvestAmount = EmployeeTaxInvestmentDA.GetAmount(tc, TaxParamID, EmployeeID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return InvestAmount;
}
public ID Save(EmployeeTaxInvestment oEmployeeTaxInvestment)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
EmployeeTaxInvestmentDA.Delete(tc, oEmployeeTaxInvestment.TaxparameterId, oEmployeeTaxInvestment.EmployeeID, oEmployeeTaxInvestment.TypeID);
if (oEmployeeTaxInvestment.IsNew)
{
int id = tc.GenerateID("ITINVESTMENT", "InvestmentID");
base.SetObjectID(oEmployeeTaxInvestment, ID.FromInteger(id));
EmployeeTaxInvestmentDA.Insert(tc, oEmployeeTaxInvestment);
}
else
{
EmployeeTaxInvestmentDA.Update(tc, oEmployeeTaxInvestment);
}
tc.End();
return oEmployeeTaxInvestment.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Save(ObjectsTemplate<EmployeeTaxInvestment> oEmployeeTaxInvestment)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
int id = tc.GenerateID("ITINVESTMENT", "InvestmentID");
foreach (EmployeeTaxInvestment eti in oEmployeeTaxInvestment)
{
base.SetObjectID(eti, ID.FromInteger(id));
if (EmployeeTaxInvestmentDA.IsExist(tc, eti.EmployeeID.Integer, eti.TaxparameterId.Integer, eti.TypeID.Integer))
{
EmployeeTaxInvestmentDA.Delete(tc, eti.EmployeeID.Integer, eti.TaxparameterId.Integer, eti.TypeID.Integer);
eti.CreatedBy = User.CurrentUser.ID;
eti.CreatedDate = DateTime.Now;
EmployeeTaxInvestmentDA.Insert(tc, eti);
}
else
{
eti.CreatedBy = User.CurrentUser.ID;
eti.CreatedDate = DateTime.Now;
EmployeeTaxInvestmentDA.Insert(tc, eti);
}
id++;
}
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(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
EmployeeTaxInvestmentDA.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
}