EchoTex_Payroll/HRM.DA/Service/Leave/EmployeeShortLeaveService.cs

326 lines
9.0 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using HRM.BO;
namespace HRM.DA
{
public class EmployeeShortLeaveService : ServiceTemplate, IEmployeeShortLeaveService
{
#region Private functions and declaration
public EmployeeShortLeaveService()
{
}
private void MapObject(EmployeeShortLeave sLeave, DataReader oReader)
{
base.SetObjectID(sLeave, oReader.GetInt32("ShortLeaveID").Value);
sLeave.EmployeeID = oReader.GetInt32("EmployeeID").Value;
sLeave.Description = oReader.GetString("Description");
sLeave.FromDate = oReader.GetDateTime("FromDate").Value;
sLeave.ToDate = oReader.GetDateTime("ToDate").Value;
sLeave.ShortLeaveType = (EnumShortLeaveType)oReader.GetInt32("ShortLeaveType");
sLeave.WillReturn = oReader.GetBoolean("WillReturn").Value;
this.SetObjectState(sLeave, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
EmployeeShortLeave sLeave = new EmployeeShortLeave();
MapObject(sLeave, oReader);
return sLeave as T;
}
private EmployeeShortLeave CreateObject(DataReader oReader)
{
EmployeeShortLeave sLeave = new EmployeeShortLeave();
MapObject(sLeave, oReader);
return sLeave;
}
#endregion
#region Service implementation
public EmployeeShortLeave Get()
{
EmployeeShortLeave sLeave = new EmployeeShortLeave();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeShortLeaveDA.Get(tc));
if (oreader.Read())
{
sLeave = this.CreateObject<EmployeeShortLeave>(oreader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get ShortLeave", e);
#endregion
}
return sLeave;
}
public EmployeeShortLeave Get(int id)
{
EmployeeShortLeave sLeave = new EmployeeShortLeave();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeShortLeaveDA.Get(tc, id));
if (oreader.Read())
{
sLeave = this.CreateObject<EmployeeShortLeave>(oreader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get ShortLeave", e);
#endregion
}
return sLeave;
}
public EmployeeShortLeave GetByType(int sLType)
{
EmployeeShortLeave sLeave = new EmployeeShortLeave();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeShortLeaveDA.Get(tc, sLType));
if (oreader.Read())
{
sLeave = this.CreateObject<EmployeeShortLeave>(oreader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get ShortLeave", e);
#endregion
}
return sLeave;
}
public EmployeeShortLeave GetByEmpID(int employeeID)
{
EmployeeShortLeave sLeave = new EmployeeShortLeave();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmployeeShortLeaveDA.Get(tc, employeeID));
if (oreader.Read())
{
sLeave = this.CreateObject<EmployeeShortLeave>(oreader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get ShortLeave", e);
#endregion
}
return sLeave;
}
public List<EmployeeShortLeave> GetByEmp(int employeeID)
{
List<EmployeeShortLeave> leaves = new List<EmployeeShortLeave>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeShortLeaveDA.GetByEmp(tc, employeeID));
leaves = this.CreateObjects<EmployeeShortLeave>(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 leaves;
}
public List<EmployeeShortLeave> Get(DateTime startTime, DateTime endTime)
{
List<EmployeeShortLeave> leaves = new List<EmployeeShortLeave>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(EmployeeShortLeaveDA.Get(tc, startTime, endTime));
leaves = this.CreateObjects<EmployeeShortLeave>(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 leaves;
}
public DataSet GetEmployeeWiseShortLeaveReport(int empId)
{
DataSet oSet;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oSet = EmployeeShortLeaveDA.GetEmployeeWiseShortLeaveReport(tc, empId);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get Report" + e.Message, e);
#endregion
}
return oSet;
}
public int Save(EmployeeShortLeave sLeave)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (sLeave.IsNew)
{
int id = tc.GenerateID("ShortLeave", "ShortLeaveID");
base.SetObjectID(sLeave, id);
EmployeeShortLeaveDA.Insert(tc, sLeave);
}
else
{
EmployeeShortLeaveDA.Update(tc, sLeave);
}
tc.End();
return sLeave.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new Exception("Failed to Insert Short Leave. Because " + e.Message, e);
#endregion
}
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
EmployeeShortLeaveDA.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
}
}