CEL_Payroll/Payroll.Service/Employee/Service/EmployeeRetirementService.cs

201 lines
5.2 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.Model;
using Payroll.BO;
using Ease.CoreV35.DataAccess;
namespace Payroll.Service
{
public class EmployeeRetirementService : ServiceTemplate, Payroll.BO.EmployeeRetirement.IEmployeeRetirementService
{
private void MapObject(EmployeeRetirement oemp, DataReader oReader)
{
base.SetObjectID(oemp, oReader.GetID("empretirementid"));
oemp.retirementAge = oReader.GetInt32("RetirementAge").Value;
oemp.employeeID = ID.FromInteger(oReader.GetInt32("employeeID").Value);
}
protected override T CreateObject<T>(DataReader oReader)
{
EmployeeRetirement oemp = new EmployeeRetirement();
MapObject(oemp, oReader);
return oemp as T;
}
protected EmployeeRetirement CreateObject(DataReader oReader)
{
EmployeeRetirement oemp = new EmployeeRetirement();
MapObject(oemp, oReader);
return oemp;
}
#region function
public ObjectsTemplate<EmployeeRetirement> Get()
{
ObjectsTemplate<EmployeeRetirement> empRetirement = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeRetirementDA.Get(tc));
empRetirement = this.CreateObjects<EmployeeRetirement>(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 empRetirement;
}
#endregion
#region IEmployeeRetirementService Members
public ID Save(EmployeeRetirement oEmployee)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oEmployee.IsNew)
{
int id = tc.GenerateID("EmployeeRetirement", "empretirementid");
base.SetObjectID(oEmployee, ID.FromInteger(id));
EmployeeRetirementDA.Insert(tc, oEmployee);
}
else
{
EmployeeRetirementDA.Update(tc, oEmployee);
}
tc.End();
return oEmployee.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void SaveAll(ObjectsTemplate<EmployeeRetirement> items)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (EmployeeRetirement iteam in items)
{
int id = tc.GenerateID("EmployeeRetirement", "empretirementid");
base.SetObjectID(iteam, ID.FromInteger(id));
EmployeeRetirementDA.Insert(tc, iteam);
}
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 UpdateAll(ObjectsTemplate<EmployeeRetirement> items)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (EmployeeRetirement iteam in items)
{
EmployeeRetirementDA.Update(tc, iteam);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int GetById(ID id)
{
TransactionContext tc = null;
int reAge = -1;
try
{
tc = TransactionContext.Begin(true);
reAge = EmployeeRetirementDA.GetAgeById(tc, id);
if (reAge != -1) return reAge;
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return reAge;
}
#endregion
}
}