CEL_Payroll/Payroll.Service/Attendence/Service/EmployeeOutsideDutyService.cs

255 lines
9.3 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.Caching;
using Ease.CoreV35.DataAccess;
using Payroll.Service.Attendence.DA;
namespace Payroll.Service.Attendence.Service
{
#region EmployeeOutsideDuty Service
[Serializable]
public class EmployeeOutsideDutyService : ServiceTemplate, IEmployeeOutsideDutyService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(EmployeeOutsideDuty));
#endregion
public EmployeeOutsideDutyService() { }
private void MapObject(EmployeeOutsideDuty oEmployeeOutsideDuty, DataReader oReader)
{
base.SetObjectID(oEmployeeOutsideDuty, oReader.GetID("EmployeeOutsideDutyID"));
oEmployeeOutsideDuty.EmployeeID = oReader.GetID("EmployeeID");
oEmployeeOutsideDuty.EntryDate = oReader.GetDateTime("EntryDate").Value;
oEmployeeOutsideDuty.StartDate = oReader.GetDateTime("StartDate").Value;
oEmployeeOutsideDuty.EndDate = oReader.GetDateTime("EndDate").Value;
oEmployeeOutsideDuty.Comments = oReader.GetString("Comments");
//oEmployeeOutsideDuty.ShiftID = oReader.GetID("ShiftID");
oEmployeeOutsideDuty.OutsideDutyID = oReader.GetID("OutsideDutyID");
oEmployeeOutsideDuty.CreatedBy = oReader.GetID("CreatedBy");
oEmployeeOutsideDuty.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oEmployeeOutsideDuty.ModifiedBy = oReader.GetID("ModifiedBy");
oEmployeeOutsideDuty.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oEmployeeOutsideDuty, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
EmployeeOutsideDuty oEmployeeOutsideDuty = new EmployeeOutsideDuty();
MapObject(oEmployeeOutsideDuty, oReader);
return oEmployeeOutsideDuty as T;
}
protected EmployeeOutsideDuty CreateObject(DataReader oReader)
{
EmployeeOutsideDuty oEmployeeOutsideDuty = new EmployeeOutsideDuty();
MapObject(oEmployeeOutsideDuty, oReader);
return oEmployeeOutsideDuty;
}
#region Service implementation
public EmployeeOutsideDuty Get(ID id)
{
EmployeeOutsideDuty oEmployeeOutsideDuty = new EmployeeOutsideDuty();
#region Cache Header
oEmployeeOutsideDuty = _cache["Get", id] as EmployeeOutsideDuty;
if (oEmployeeOutsideDuty != null)
return oEmployeeOutsideDuty;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeOutsideDutyDA.Get(tc, id));
if (oreader.Read())
{
oEmployeeOutsideDuty = this.CreateObject<EmployeeOutsideDuty>(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(oEmployeeOutsideDuty, "Get", id);
#endregion
return oEmployeeOutsideDuty;
}
public ObjectsTemplate<EmployeeOutsideDuty> Get()
{
#region Cache Header
ObjectsTemplate<EmployeeOutsideDuty> employeeOutsideDutys = _cache["Get"] as ObjectsTemplate<EmployeeOutsideDuty>;
if (employeeOutsideDutys != null)
return employeeOutsideDutys;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeOutsideDutyDA.Get(tc));
employeeOutsideDutys = this.CreateObjects<EmployeeOutsideDuty>(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(employeeOutsideDutys, "Get");
#endregion
return employeeOutsideDutys;
}
public ObjectsTemplate<EmployeeOutsideDuty> GetByEmpID(ID empID)
{
#region Cache Header
ObjectsTemplate<EmployeeOutsideDuty> employeeOutsideDutys = _cache["Get", empID] as ObjectsTemplate<EmployeeOutsideDuty>;
if (employeeOutsideDutys != null)
return employeeOutsideDutys;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeOutsideDutyDA.GetByEmpID(tc, empID));
employeeOutsideDutys = this.CreateObjects<EmployeeOutsideDuty>(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(employeeOutsideDutys, "Get", empID);
#endregion
return employeeOutsideDutys;
}
public ObjectsTemplate<EmployeeOutsideDuty> Get(DateTime attnDate)
{
#region Cache Header
ObjectsTemplate<EmployeeOutsideDuty> employeeOutsideDutys = _cache["Get", attnDate] as ObjectsTemplate<EmployeeOutsideDuty>;
if (employeeOutsideDutys != null)
return employeeOutsideDutys;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeOutsideDutyDA.Get(tc, attnDate));
employeeOutsideDutys = this.CreateObjects<EmployeeOutsideDuty>(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(employeeOutsideDutys, "Get", attnDate);
#endregion
return employeeOutsideDutys;
}
public ID Save(EmployeeOutsideDuty oEmployeeOutsideDuty)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oEmployeeOutsideDuty.IsNew)
{
int id = tc.GenerateID("EmployeeOutsideDuty", "EmployeeOutsideDutyID");
base.SetObjectID(oEmployeeOutsideDuty, ID.FromInteger(id));
EmployeeOutsideDutyDA.Insert(tc, oEmployeeOutsideDuty);
}
else
{
EmployeeOutsideDutyDA.Update(tc, oEmployeeOutsideDuty);
}
tc.End();
return oEmployeeOutsideDuty.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);
EmployeeOutsideDutyDA.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 bool IsOutsideDutyAvailable(DateTime startDate, DateTime endDate, ID empID)
{
bool isExist = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
isExist = EmployeeOutsideDutyDA.IsOutsideDutyAvailable(tc, startDate, endDate, empID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return isExist;
}
#endregion
}
#endregion
}