CEL_Payroll/Payroll.Service/Employee/Service/EmployeeConfirmationService.cs

219 lines
7.1 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
{
[Serializable]
public class EmployeeConfirmationService : ServiceTemplate, IEmployeeConfirmationService
{
#region Cache
Cache _cache = new Cache(typeof(EmployeeBankAccount));
#endregion
#region Map Functions
private void MapObject(EmployeeConfirmation oEmployeeConfirmation, DataReader oReader)
{
base.SetObjectID(oEmployeeConfirmation, oReader.GetID("EmpConfirmID"));
oEmployeeConfirmation.EmployeeID = oReader.GetID("EmployeeID");
oEmployeeConfirmation.Month = oReader.GetInt32("Month").Value;
oEmployeeConfirmation.ConfirmDate = oReader.GetDateTime("ConfirmDate").GetValueOrDefault();
oEmployeeConfirmation.CreatedBy = oReader.GetID("CreatedBy");
oEmployeeConfirmation.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oEmployeeConfirmation.ModifiedBy = oReader.GetID("ModifiedBy");
oEmployeeConfirmation.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oEmployeeConfirmation, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
EmployeeConfirmation oEmployeeConfirmation = new EmployeeConfirmation();
MapObject(oEmployeeConfirmation, dr);
return oEmployeeConfirmation as T;
}
#endregion
#region IEmployeeConfirmationService Members
public EmployeeConfirmation Get(ID nID)
{
EmployeeConfirmation oEmployeeConfirmation = new EmployeeConfirmation();
#region Cache Header
oEmployeeConfirmation = _cache["Get", nID] as EmployeeConfirmation;
if (oEmployeeConfirmation != null)
return oEmployeeConfirmation;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeConfirmationDA.Get(tc, nID));
if (oreader.Read())
{
oEmployeeConfirmation = this.CreateObject<EmployeeConfirmation>(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(oEmployeeConfirmation, "Get", nID);
#endregion
return oEmployeeConfirmation;
}
public EmployeeConfirmation GetByEmployeeID(ID nID)
{
EmployeeConfirmation oEmployeeConfirmation = new EmployeeConfirmation();
#region Cache Header
oEmployeeConfirmation = _cache["Get", nID] as EmployeeConfirmation;
if (oEmployeeConfirmation != null)
return oEmployeeConfirmation;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeConfirmationDA.GetByEmployeeID(tc, nID));
if (oreader.Read())
{
oEmployeeConfirmation = this.CreateObject<EmployeeConfirmation>(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(oEmployeeConfirmation, "Get", nID);
#endregion
return oEmployeeConfirmation;
}
public ObjectsTemplate<EmployeeConfirmation> Get()
{
#region Cache Header
ObjectsTemplate<EmployeeConfirmation> employeeConfirmations = _cache["Get"] as ObjectsTemplate<EmployeeConfirmation>;
if (employeeConfirmations != null)
return employeeConfirmations;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeConfirmationDA.Get(tc));
employeeConfirmations = this.CreateObjects<EmployeeConfirmation>(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(employeeConfirmations, "Get");
#endregion
return employeeConfirmations;
}
public ID Save(EmployeeConfirmation employeeConfirmation)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
EmployeeService empservice = new EmployeeService();
if (employeeConfirmation.IsNew)
{
EmployeeConfirmationDA.DeleteByEmployeeID(tc,employeeConfirmation.EmployeeID);
int id = tc.GenerateID("EmpConfirmation", "EmpConfirmID");
base.SetObjectID(employeeConfirmation, ID.FromInteger(id));
EmployeeConfirmationDA.Insert(tc, employeeConfirmation);
}
else
{
EmployeeConfirmationDA.Update(tc, employeeConfirmation);
}
tc.End();
return employeeConfirmation.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(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
EmployeeConfirmationDA.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
}
}