EchoTex_Payroll/HRM.DA/Service/Tax/TaxHeadAssignmentService.cs
2024-10-14 10:01:49 +06:00

163 lines
4.9 KiB
C#

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;
using System;
namespace HRM.DA
{
public class TaxHeadAssignmentService : ServiceTemplate, ITaxHeadAssignmentService
{
public TaxHeadAssignmentService()
{
}
private void MapObject(TaxHeadAssignment oTaxHeadAssignment, DataReader oReader)
{
base.SetObjectID(oTaxHeadAssignment, oReader.GetInt32("HeadID").Value);
//oTaxHeadAssignment.HeadType = oReader.GetInt32("headType").Value;
oTaxHeadAssignment.Description = oReader.GetString("description");
oTaxHeadAssignment.DeductPercent = oReader.GetDouble("deductPercent").Value;
oTaxHeadAssignment.Sequence = oReader.GetInt32("SequenceNO").Value;
oTaxHeadAssignment.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oTaxHeadAssignment.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oTaxHeadAssignment.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oTaxHeadAssignment.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oTaxHeadAssignment.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oTaxHeadAssignment, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
TaxHeadAssignment oTaxHeadAssignment = new TaxHeadAssignment();
MapObject(oTaxHeadAssignment, oReader);
return oTaxHeadAssignment as T;
}
#region Service implementation
public TaxHeadAssignment Get(int id)
{
TaxHeadAssignment oTaxHeadAssignment = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TaxHeadAssignmentDA.Get(tc, id));
if (oreader.Read())
{
oTaxHeadAssignment = this.CreateObject<TaxHeadAssignment>(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 oTaxHeadAssignment;
}
public List<TaxHeadAssignment> Get()
{
List<TaxHeadAssignment> taxHeadAssignments = new List<TaxHeadAssignment>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TaxHeadAssignmentDA.Get(tc));
taxHeadAssignments = this.CreateObjects<TaxHeadAssignment>(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 taxHeadAssignments;
}
public int Save(TaxHeadAssignment oTaxHeadAssignment)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oTaxHeadAssignment.IsNew)
{
int id = tc.GenerateID("INCOMETAXHEAD", "HeadID");
base.SetObjectID(oTaxHeadAssignment, (id));
TaxHeadAssignmentDA.Insert(tc, oTaxHeadAssignment);
}
else
{
TaxHeadAssignmentDA.Update(tc, oTaxHeadAssignment);
}
tc.End();
return oTaxHeadAssignment.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);
TaxHeadAssignmentDA.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
}
}