175 lines
5.5 KiB
C#
175 lines
5.5 KiB
C#
using Ease.Core.DataAccess;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.Utility;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using HRM.BO;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
public class UploadEncashAmountService : ServiceTemplate, IUploadEncashAmountService
|
|
{
|
|
#region Private functions and declaration
|
|
|
|
public UploadEncashAmountService()
|
|
{
|
|
}
|
|
|
|
private void MapObject(UploadEncashAmount oUploadEncashAmount, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oUploadEncashAmount, oReader.GetInt32("UploadEncashAmountID").Value);
|
|
|
|
oUploadEncashAmount.EmployeeID =
|
|
oReader.GetString("EmployeeID") == null ? 0 : oReader.GetInt32("EmployeeID").Value;
|
|
oUploadEncashAmount.LeaveID = oReader.GetString("LeaveID") == null ? 0 : oReader.GetInt32("LeaveID").Value;
|
|
oUploadEncashAmount.LeaveYear = oReader.GetInt16("LeaveYear").Value;
|
|
oUploadEncashAmount.Days = oReader.GetInt16("Days").Value;
|
|
oUploadEncashAmount.BasicSalary = oReader.GetDouble("BasicSalary").Value;
|
|
this.SetObjectState(oUploadEncashAmount, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
UploadEncashAmount oUploadEncashAmount = new UploadEncashAmount();
|
|
MapObject(oUploadEncashAmount, oReader);
|
|
return oUploadEncashAmount as T;
|
|
}
|
|
|
|
private UploadEncashAmount CreateObject(DataReader oReader)
|
|
{
|
|
UploadEncashAmount oUploadEncashAmount = new UploadEncashAmount();
|
|
MapObject(oUploadEncashAmount, oReader);
|
|
return oUploadEncashAmount;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
|
|
public void Save(List<UploadEncashAmount> items)
|
|
{
|
|
List<UploadEncashAmount> prevItems = this.Get();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
foreach (UploadEncashAmount item in items)
|
|
{
|
|
UploadEncashAmount oItem = prevItems.Find(delegate(UploadEncashAmount ea)
|
|
{
|
|
return ea.EmployeeID == item.EmployeeID && ea.LeaveID == item.LeaveID &&
|
|
ea.LeaveYear == item.LeaveYear;
|
|
});
|
|
if (oItem == null)
|
|
{
|
|
int id = tc.GenerateID("UploadEncashAmount", "UploadEncashAmountID");
|
|
base.SetObjectID(item, id);
|
|
UploadEncashAmountDA.Insert(tc, item);
|
|
}
|
|
else
|
|
{
|
|
base.SetObjectID(item, oItem.ID);
|
|
UploadEncashAmountDA.Update(tc, item);
|
|
}
|
|
}
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException("Failed to Insert Leave Year: " + e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#region Delete Service
|
|
|
|
public void Delete(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
UploadEncashAmountDA.Delete(id, tc);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new Exception("Failed to Insert UploadEncashAmount due to " + e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public List<UploadEncashAmount> Get(int empID)
|
|
{
|
|
List<UploadEncashAmount> oUploadEncashAmounts = new List<UploadEncashAmount>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(UploadEncashAmountDA.Get(tc, empID));
|
|
oUploadEncashAmounts = this.CreateObjects<UploadEncashAmount>(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 oUploadEncashAmounts;
|
|
}
|
|
|
|
public List<UploadEncashAmount> Get()
|
|
{
|
|
List<UploadEncashAmount> oUploadEncashAmounts = new List<UploadEncashAmount>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(UploadEncashAmountDA.Get(tc));
|
|
oUploadEncashAmounts = this.CreateObjects<UploadEncashAmount>(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 oUploadEncashAmounts;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |