CEL_Payroll/Payroll.Service/OPI/Service/PremiumSetupService.cs

142 lines
4.5 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
[Serializable]
public class PremiumSetupService : ServiceTemplate, IPremiumSetupService
{
private void MapObject(PremiumSetup oPremiumSetup, DataReader oReader)
{
base.SetObjectID(oPremiumSetup, oReader.GetID("PremiumSetupID"));
oPremiumSetup.Factor = oReader.GetDouble("Factor").HasValue ? oReader.GetDouble("Factor").Value : 0;
oPremiumSetup.PremiumRate = oReader.GetDouble("PremiumRate").HasValue ? oReader.GetDouble("PremiumRate").Value : 0;
this.SetObjectState(oPremiumSetup, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
PremiumSetup oPremiumSetup = new PremiumSetup();
MapObject(oPremiumSetup, oReader);
return oPremiumSetup as T;
}
protected PremiumSetup CreateObject(DataReader oReader)
{
PremiumSetup oPremiumSetup = new PremiumSetup();
MapObject(oPremiumSetup, oReader);
return oPremiumSetup;
}
public PremiumSetup Get(ID id)
{
PremiumSetup oPremiumSetup = new PremiumSetup();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oReader = new DataReader(PremiumSetupDA.Get(tc, id));
if (oReader.Read())
{
oPremiumSetup = this.CreateObject(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 oPremiumSetup;
}
public ObjectsTemplate<PremiumSetup> Get()
{
ObjectsTemplate<PremiumSetup> oPremiumSetups = new ObjectsTemplate<PremiumSetup>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PremiumSetupDA.Get(tc));
oPremiumSetups = this.CreateObjects<PremiumSetup>(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 oPremiumSetups;
}
public ID Save(PremiumSetup oPremiumSetup)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
PremiumSetupDA.Delete(tc);
if (oPremiumSetup.IsNew)
{
int id = tc.GenerateID("PremiumSetup", "PremiumSetupID");
base.SetObjectID(oPremiumSetup, ID.FromInteger(id));
PremiumSetupDA.Insert(tc, oPremiumSetup);
}
else
{
PremiumSetupDA.Update(tc, oPremiumSetup);
}
tc.End();
return oPremiumSetup.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(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
PremiumSetupDA.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
}
}
}
}