EchoTex_Payroll/HRM.DA/Service/Workflow/DelegateResponsibolityService.cs

373 lines
12 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core.Utility;
using System.Collections.Generic;
using HRM.BO;
using System.Data;
using Ease.Core;
namespace HRM.DA
{
public class DelegateResponsibilityService : ServiceTemplate, IDelegateResponsibilityService
{
#region Private functions and declaration
public DelegateResponsibilityService()
{
}
private void MapObject(DelegateResponsibility delegateResponsibility, DataReader oReader)
{
base.SetObjectID(delegateResponsibility, (oReader.GetInt32("DelegateResponsibilityID").Value));
delegateResponsibility.FromEmployeeID = oReader.GetInt32("FromEmployeeID", 0);
delegateResponsibility.ToEmployeeID = oReader.GetInt32("ToEmployeeID", 0);
delegateResponsibility.FromDate = oReader.GetDateTime("FromDate").Value;
delegateResponsibility.ToDate = oReader.GetDateTime("ToDate").Value;
delegateResponsibility.IsLeave = oReader.GetBoolean("IsLeave").Value;
delegateResponsibility.IsLoan = oReader.GetBoolean("IsLoan").Value;
delegateResponsibility.IsAttendance = oReader.GetBoolean("IsAttendance").Value;
delegateResponsibility.IsAccepted = oReader.GetBoolean("IsAccepted").Value;
delegateResponsibility.IsUnlimited = oReader.GetBoolean("IsUnlimited").Value;
delegateResponsibility.IsRead = oReader.GetBoolean("IsRead").Value;
delegateResponsibility.Remarks = oReader.GetString("Remarks");
delegateResponsibility.CreatedBy = (oReader.GetInt32("CreatedBy").Value);
delegateResponsibility.CreatedDate = oReader.GetDateTime("CreationDate").Value;
delegateResponsibility.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
delegateResponsibility.ModifiedDate = oReader.GetDateTime("ModifiedDate");
delegateResponsibility.Status = (EnumStatus)oReader.GetInt32("Status").Value;
this.SetObjectState(delegateResponsibility, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
DelegateResponsibility batGrandTag = new DelegateResponsibility();
MapObject(batGrandTag, oReader);
return batGrandTag as T;
}
private DelegateResponsibility CreateObject(DataReader oReader)
{
DelegateResponsibility batGrandTag = new DelegateResponsibility();
MapObject(batGrandTag, oReader);
return batGrandTag;
}
#endregion
#region Service implementation
public List<DelegateResponsibility> GetWithPayrollType(int payrollTypeID)
{
List<DelegateResponsibility> batGrandTags = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DelegateResponsibilityDA.Get(tc, payrollTypeID));
batGrandTags = this.CreateObjects<DelegateResponsibility>(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 batGrandTags;
}
public List<DelegateResponsibility> GetByToEmployeeID(TransactionContext tc, int empID)
{
List<DelegateResponsibility> delegateRes = null;
try
{
DataReader dr = new DataReader(DelegateResponsibilityDA.GetByToEmployeeID(tc, empID));
delegateRes = this.CreateObjects<DelegateResponsibility>(dr);
dr.Close();
}
catch (Exception e)
{
#region Handle Exception
throw new ServiceException(e.Message, e);
#endregion
}
return delegateRes;
}
public List<DelegateResponsibility> GetByEmployeeID(int empID)
{
List<DelegateResponsibility> delegateRes = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DelegateResponsibilityDA.GetByEmployeeID(tc, empID));
delegateRes = this.CreateObjects<DelegateResponsibility>(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 delegateRes;
}
public DelegateResponsibility Get(int employeeid, int payrollTypeID)
{
TransactionContext tc = null;
DelegateResponsibility batGrandTag = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DelegateResponsibilityDA.Get(tc, employeeid, payrollTypeID));
if (dr.Read())
{
batGrandTag = this.CreateObject(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 batGrandTag;
}
public List<DelegateResponsibility> Get(string ids, int payrollTypeID)
{
List<DelegateResponsibility> batGrandTags = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DelegateResponsibilityDA.Get(tc, ids, payrollTypeID));
batGrandTags = this.CreateObjects<DelegateResponsibility>(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 batGrandTags;
}
public DelegateResponsibility Get(int id)
{
TransactionContext tc = null;
DelegateResponsibility delegateRes = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DelegateResponsibilityDA.Get(tc, id));
if (dr.Read())
{
delegateRes = this.CreateObject(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 delegateRes;
}
public void Save(List<DelegateResponsibility> batGrandTags)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (DelegateResponsibility batTaging in batGrandTags)
{
int id = tc.GenerateID("DelegateResponsibility", "TagingID");
base.SetObjectID(batTaging, (id));
if (DelegateResponsibilityDA.IsExist(tc, batTaging.ToEmployeeID))
{
batTaging.ModifiedBy = batTaging.ModifiedBy;
batTaging.ModifiedDate = DateTime.Now;
DelegateResponsibilityDA.Update(tc, batTaging);
}
else
{
DelegateResponsibilityDA.Insert(tc, batTaging);
}
}
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 Save(DelegateResponsibility oDelegateResponsibility)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oDelegateResponsibility.IsNew)
{
int id = tc.GenerateID("DelegateResponsibility", "DelegateResponsibilityID");
base.SetObjectID(oDelegateResponsibility, (id));
DelegateResponsibilityDA.Insert(tc, oDelegateResponsibility);
}
else
{
DelegateResponsibilityDA.Update(tc, oDelegateResponsibility);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
//throw new ServiceException("Failed to Get Leave", e);
throw new Exception("Failed to Insert Leave. Because " + e.Message, e);
#endregion
}
}
public void UpdateReadStatus(int objID, bool isRead)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DelegateResponsibilityDA.UpdateReadStatus(tc, objID, isRead);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
//throw new ServiceException("Failed to Get Leave", e);
throw new Exception("Failed to update. Because " + e.Message, e);
#endregion
}
}
public void UpdateStatus(int objID, EnumStatus status)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DelegateResponsibilityDA.UpdateStatus(tc, objID, status);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
//throw new ServiceException("Failed to Get Leave", e);
throw new Exception("Failed to update. Because " + e.Message, e);
#endregion
}
}
public void Delete(string empId)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DelegateResponsibilityDA.Delete(tc, empId);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
}