EchoTex_Payroll/HRM.DA/Service/AllowDeduct/ComponentUploadSetupService.cs

184 lines
5.2 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 System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
public class ComponentUploadSetupService : ServiceTemplate, IComponentUploadSetupService
{
#region Private functions and declaration
public ComponentUploadSetupService()
{
}
private void MapObject(ComponentUploadSetup componentSetup, DataReader oReader)
{
base.SetObjectID(componentSetup, oReader.GetInt32("ComponentUploadSetupID").Value);
componentSetup.EmployeeID = oReader.GetInt32("EmployeeID").Value;
componentSetup.ItemID = oReader.GetInt32("ItemID", 0);
componentSetup.ComponentType = (EnumComponentType)oReader.GetInt32("ComponentType");
componentSetup.Description = oReader.GetString("Description");
this.SetObjectState(componentSetup, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ComponentUploadSetup componentSetup = new ComponentUploadSetup();
MapObject(componentSetup, oReader);
return componentSetup as T;
}
#endregion
#region Service implementation
public List<ComponentUploadSetup> Get()
{
List<ComponentUploadSetup> componentSetups = new List<ComponentUploadSetup>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ComponentUploadSetupDA.Get(tc));
componentSetups = this.CreateObjects<ComponentUploadSetup>(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 componentSetups;
}
public List<ComponentUploadSetup> Get(int empid)
{
List<ComponentUploadSetup> componentSetups = new List<ComponentUploadSetup>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ComponentUploadSetupDA.Get(tc, empid));
componentSetups = this.CreateObjects<ComponentUploadSetup>(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 componentSetups;
}
public int Save(ComponentUploadSetup componentSetup)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (componentSetup.IsNew)
{
int id = tc.GenerateID("ComponentUploadSetup", "ComponentUploadSetupID");
base.SetObjectID(componentSetup, (id));
ComponentUploadSetupDA.Insert(tc, componentSetup);
}
else
{
ComponentUploadSetupDA.Update(tc, componentSetup);
}
tc.End();
return componentSetup.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new Exception("Failed to Component Upload Setup. Because " + e.Message, e);
#endregion
}
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ComponentUploadSetupDA.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 IsExist(int empId, EnumComponentType ComponentType, int itemId)
{
bool Exist = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
Exist = ComponentUploadSetupDA.IsExist(tc, empId, ComponentType, itemId);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return Exist;
}
#endregion
}
}