EchoTex_Payroll/HRM.DA/Service/HRBasic/DivisionService.cs

261 lines
6.8 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 HRM.BO;
using System.Collections.Generic;
using Ease.Core.Utility;
namespace HRM.DA
{
public class DivisionService : ServiceTemplate, IDivisionService
{
#region constructor
public DivisionService()
{
}
#endregion
#region Object
private void MapObject(Division oDivision, DataReader oReader)
{
base.SetObjectID(oDivision, oReader.GetInt32("DIVISIONID").Value);
oDivision.Code = oReader.GetString("CODE");
oDivision.Name = oReader.GetString("NAME");
oDivision.Sequence = oReader.GetInt32("SequenceNo").Value;
oDivision.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oDivision.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oDivision.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oDivision.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oDivision.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oDivision, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Division oDivision = new Division();
MapObject(oDivision, oReader);
return oDivision as T;
}
#endregion
#region Service implementation
public Division Get(int id)
{
Division oDivision = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DivisionDA.Get(tc, id));
if (oreader.Read())
{
oDivision = this.CreateObject<Division>(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 oDivision;
}
public Division Get(string sCode)
{
Division oDivision = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DivisionDA.Get(tc, sCode));
if (oreader.Read())
{
oDivision = this.CreateObject<Division>(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 oDivision;
}
public List<Division> Get()
{
List<Division> countries = new List<Division>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DivisionDA.Get(tc));
countries = this.CreateObjects<Division>(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 countries;
}
public List<Division> Get(EnumStatus status)
{
List<Division> countries = new List<Division>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DivisionDA.Get(tc, status));
countries = this.CreateObjects<Division>(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 countries;
}
public List<Division> Get(EnumStatus status, int payrollTypeId)
{
List<Division> countries = new List<Division>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DivisionDA.Get(tc, status));
countries = this.CreateObjects<Division>(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 countries;
}
public int Save(Division oDivision)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oDivision.IsNew)
{
int id = tc.GenerateID("DIVISION", "DIVISIONID");
base.SetObjectID(oDivision, id);
DivisionDA.Insert(tc, oDivision);
}
else
{
DivisionDA.Update(tc, oDivision);
}
tc.End();
return oDivision.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);
DivisionDA.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
}
}