CEL_Payroll/Payroll.Service/Organogram/Service/OrganogramEmployeeService.cs

357 lines
12 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 OrganogramEmployee Service
[Serializable]
public class OrganogramEmployeeService : ServiceTemplate, IOrganogramEmployeeService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(OrganogramEmployee));
#endregion
public OrganogramEmployeeService()
{ }
private void MapObject(OrganogramEmployee oOrganEmp, DataReader oReader)
{
//base.SetObjectID(oOrganEmp,ID.FromComplex(oReader.GetID("NodeID"),oReader.GetID("EmployeeID")));
base.SetObjectID(oOrganEmp, oReader.GetID("OrganEmpID"));
oOrganEmp.NodeID = oReader.GetID("NodeID");
oOrganEmp.EmployeeID = oReader.GetID("EmployeeID");
oOrganEmp.AssignDate = oReader.GetDateTime("AssignDate").Value;
oOrganEmp.CreatedBy = oReader.GetID("CreatedBy");
oOrganEmp.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oOrganEmp.ModifiedBy = oReader.GetID("ModifiedBy");
//oOrganEmp.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value;
this.SetObjectState(oOrganEmp, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
OrganogramEmployee oOrganogramEmployee = new OrganogramEmployee();
MapObject(oOrganogramEmployee, oReader);
return oOrganogramEmployee as T;
}
protected OrganogramEmployee CreateObject(DataReader oReader)
{
OrganogramEmployee oOrganogramEmployee = new OrganogramEmployee();
MapObject(oOrganogramEmployee, oReader);
return oOrganogramEmployee;
}
#region Service implementation
public ID Save(OrganogramEmployee oOrganogramEmployee)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
Save(oOrganogramEmployee);
tc.End();
}
catch(Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oOrganogramEmployee.ID;
}
public void SaveEmp(ObjectsTemplate<OrganogramEmployee> oOrganogramEmployees)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (OrganogramEmployee orgEmp in oOrganogramEmployees)
{
if (orgEmp.IsNew)
{
int id = tc.GenerateID("OrganEmployee", "OrganEmpID");
base.SetObjectID(orgEmp, ID.FromInteger(id));
orgEmp.CreatedBy = User.CurrentUser.ID;
orgEmp.CreatedDate = DateTime.Today;
OrganogramEmployeeDA.Insert(tc, orgEmp);
}
else
{
orgEmp.ModifiedBy = User.CurrentUser.ID;
orgEmp.ModifiedDate = DateTime.Today;
OrganogramEmployeeDA.Update(tc, orgEmp);
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public ID Save(TransactionContext tc, OrganogramEmployee oOrganogramEmployee)
{
try
{
if (oOrganogramEmployee.IsNew)
{
int id = tc.GenerateID("OrganEmployee", "OrganEmpID");
base.SetObjectID(oOrganogramEmployee, ID.FromInteger(id));
OrganogramEmployeeDA.Insert(tc, oOrganogramEmployee);
}
else
{
OrganogramEmployeeDA.Update(tc, oOrganogramEmployee);
}
return oOrganogramEmployee.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
//public static void SaveForEmpLIfeCycle(TransactionContext tc, OrganogramEmployee oOrganogramEmployee)
//{
// try
// {
// int id = tc.GenerateID("OrganEmployee", "OrganEmpID");
// OrganogramEmployeeDA.InsertForLifeCycle(tc, oOrganogramEmployee,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);
OrganogramEmployeeDA.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
}
}
public void DeleteByEmp(TransactionContext tc, ID id)
{
try
{
OrganogramEmployeeDA.DeleteByEmp(tc, id);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public ObjectsTemplate<OrganogramEmployee> Get(TransactionContext tc, ID nodeID)
{
ObjectsTemplate<OrganogramEmployee> oOrganogramEmployee = new ObjectsTemplate<OrganogramEmployee>();
#region Cache Header
oOrganogramEmployee = _cache["Get", nodeID] as ObjectsTemplate<OrganogramEmployee>;
if (oOrganogramEmployee != null)
return oOrganogramEmployee;
#endregion
try
{
DataReader dr = new DataReader(OrganogramEmployeeDA.Get(tc, nodeID));
oOrganogramEmployee = this.CreateObjects<OrganogramEmployee>(dr);
dr.Close();
}
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(oOrganogramEmployee, "Get", nodeID);
#endregion
return oOrganogramEmployee;
}
public ObjectsTemplate<OrganogramEmployee> GetByEmp(ID empID)
{
ObjectsTemplate<OrganogramEmployee> oOrganogramEmployee = new ObjectsTemplate<OrganogramEmployee>();
#region Cache Header
oOrganogramEmployee = _cache["GetByEmp", empID] as ObjectsTemplate<OrganogramEmployee>;
if (oOrganogramEmployee != null)
return oOrganogramEmployee;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OrganogramEmployeeDA.GetByEmp(tc, empID));
oOrganogramEmployee = this.CreateObjects<OrganogramEmployee>(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(oOrganogramEmployee, "GetByEmp", empID);
#endregion
return oOrganogramEmployee;
}
public ObjectsTemplate<OrganogramEmployee> Get(ID nodeID)
{
ObjectsTemplate<OrganogramEmployee> oOrganogramEmployee = new ObjectsTemplate<OrganogramEmployee>();
#region Cache Header
oOrganogramEmployee = _cache["Get", nodeID] as ObjectsTemplate<OrganogramEmployee>;
if (oOrganogramEmployee != null)
return oOrganogramEmployee;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OrganogramEmployeeDA.Get(tc, nodeID));
oOrganogramEmployee = this.CreateObjects<OrganogramEmployee>(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(oOrganogramEmployee, "Get", nodeID);
#endregion
return oOrganogramEmployee;
}
public ObjectsTemplate<OrganogramEmployee> Get()
{
#region Cache Header
ObjectsTemplate<OrganogramEmployee> oOrganogramEmployee = _cache["Get"] as ObjectsTemplate<OrganogramEmployee>;
if (oOrganogramEmployee != null)
return oOrganogramEmployee;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OrganogramEmployeeDA.Get(tc));
oOrganogramEmployee = this.CreateObjects<OrganogramEmployee>(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(oOrganogramEmployee, "Get");
#endregion
return oOrganogramEmployee;
}
public ObjectsTemplate<OrganogramEmployee> GetByPositionType(EnumOGPositionType enPositionType)
{
#region Cache Header
ObjectsTemplate<OrganogramEmployee> oOrganogramEmployee = _cache["GetByPositionType", enPositionType] as ObjectsTemplate<OrganogramEmployee>;
if (oOrganogramEmployee != null)
return oOrganogramEmployee;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OrganogramEmployeeDA.GetByPositionType(tc, enPositionType));
oOrganogramEmployee = this.CreateObjects<OrganogramEmployee>(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(oOrganogramEmployee, "GetByPositionType", enPositionType);
#endregion
return oOrganogramEmployee;
}
#endregion
}
#endregion
}