EchoTex_Payroll/HRM.DA/Service/Basic/ProcessItemService.cs
2024-10-14 10:01:49 +06:00

191 lines
5.2 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
{
#region ProcessItem Service
public class ProcessItemService : ServiceTemplate, IProcessItemService
{
public ProcessItemService()
{
}
private void MapObject(ProcessItem oProcessItem, DataReader oReader)
{
base.SetObjectID(oProcessItem, oReader.GetInt32("ProcessItemID").Value);
oProcessItem.ItemCode = oReader.GetInt32("itemCode").Value;
oProcessItem.DefaultDescription = oReader.GetString("defaultDescription");
oProcessItem.UserDescription = oReader.GetString("userDescription");
oProcessItem.Position = oReader.GetInt32("position").Value;
oProcessItem.ItemGroup = oReader.GetInt32("itemGroup").Value;
this.SetObjectState(oProcessItem, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ProcessItem oProcessItem = new ProcessItem();
MapObject(oProcessItem, oReader);
return oProcessItem as T;
}
#region Service implementation
public ProcessItem Get(int id)
{
ProcessItem oProcessItem = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ProcessItemDA.Get(tc, id));
if (oreader.Read())
{
oProcessItem = this.CreateObject<ProcessItem>(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
}
return oProcessItem;
}
public List<ProcessItem> Get()
{
List<ProcessItem> processItems = new List<ProcessItem>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ProcessItemDA.Get(tc));
processItems = this.CreateObjects<ProcessItem>(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 processItems;
}
public List<ProcessItem> GetForTHeadGroup()
{
List<ProcessItem> processItems = new List<ProcessItem>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ProcessItemDA.GetForTHeadGroup(tc));
processItems = this.CreateObjects<ProcessItem>(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 processItems;
}
public int Save(ProcessItem oProcessItem)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oProcessItem.IsNew)
{
int id = tc.GenerateID("ProcessItem", "ProcessItemID");
base.SetObjectID(oProcessItem, id);
ProcessItemDA.Insert(tc, oProcessItem);
}
else
{
ProcessItemDA.Update(tc, oProcessItem);
}
tc.End();
return oProcessItem.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(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ProcessItemDA.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
}
#endregion
}