EchoTex_Payroll/HRM.DA/Service/GrievanceManagement/PunishmentService.cs

222 lines
6.1 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using System.Linq;
using Ease.Core;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using System.Collections.Generic;
using HRM.BO;
using Ease.Core.Utility;
namespace HRM.DA
{
#region Punishment Service
[Serializable]
public class PunishmentService : ServiceTemplate, IPunishmentService
{
public PunishmentService() { }
private void MapObject(Punishment oPunishment, DataReader oReader)
{
base.SetObjectID(oPunishment, oReader.GetInt32("PunishmentID").Value);
oPunishment.Code = oReader.GetString("code");
oPunishment.Description = oReader.GetString("Description");
this.SetObjectState(oPunishment, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Punishment oPunishment = new Punishment();
MapObject(oPunishment, oReader);
return oPunishment as T;
}
protected Punishment CreateObject(DataReader oReader)
{
Punishment oPunishment = new Punishment();
MapObject(oPunishment, oReader);
return oPunishment;
}
#region Service implementation
public Punishment Get(int id)
{
Punishment oPunishment = new Punishment();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PunishmentDA.Get(tc, id));
if (oreader.Read())
{
oPunishment = this.CreateObject<Punishment>(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 oPunishment;
}
public List<Punishment> Get()
{
#region
List<Punishment> religions = new List<Punishment>();
//if (religions != null)
// return religions;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PunishmentDA.Get(tc));
religions = this.CreateObjects<Punishment>(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 religions;
}
public List<Punishment> Get(EnumStatus status)
{
#region Cache Header
List<Punishment> punishments = new List<Punishment>();
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PunishmentDA.Get(tc, status));
punishments = this.CreateObjects<Punishment>(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 punishments;
}
public List<Punishment> GetDAPunishmentPicker(int punishmentid)
{
List<Punishment> Punishments = new List<Punishment>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PunishmentDA.GetDAPunishmentPicker(tc, punishmentid));
Punishments = this.CreateObjects<Punishment>(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 Punishments;
}
public int Save(Punishment oPunishment)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oPunishment.IsNew)
{
int id = tc.GenerateID("Punishment", "PunishmentID");
base.SetObjectID(oPunishment, id);
PunishmentDA.Insert(tc, oPunishment);
}
else
{
PunishmentDA.Update(tc, oPunishment);
}
tc.End();
return oPunishment.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);
PunishmentDA.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
}