EchoTex_Payroll/HRM.DA/Service/SearchTools/ObjectGroupingService.cs

185 lines
4.6 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 Ease.Core.Utility;
using System.Collections.Generic;
using HRM.BO;
using System.Data;
namespace HRM.DA
{
public class ObjectGroupingService : ServiceTemplate
{
#region Constructor
public ObjectGroupingService()
{
}
#endregion
private void MapObject(ObjectGrouping oObjectGrouping, DataReader dr)
{
base.SetObjectID(oObjectGrouping, dr.GetInt32("GroupingId").Value);
oObjectGrouping.Name = dr.GetString("Name");
this.SetObjectState(oObjectGrouping, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
ObjectGrouping oObjectGrouping = new ObjectGrouping();
MapObject(oObjectGrouping, dr);
return oObjectGrouping as T;
}
#region Service Implementation
public void Save(ObjectGrouping objectGrouping)
{
try
{
TransactionContext tc = null;
try
{
#region Saving data
tc = TransactionContext.Begin(true);
if (objectGrouping.IsNew)
{
int newID = ObjectGroupingDA.GenID(tc);
base.SetObjectID(objectGrouping, newID);
ObjectGroupingDA.Insert(tc, objectGrouping);
}
else
ObjectGroupingDA.Update(tc, objectGrouping);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
throw new ServiceException(e.Message, e);
}
}
public void Delete(int objectGroupingID)
{
{
try
{
TransactionContext tc = null;
try
{
#region Deleting data
tc = TransactionContext.Begin(true);
ObjectGroupingDA.Delete(tc, objectGroupingID);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
throw new ServiceException(e.Message, e);
}
}
}
public ObjectGrouping Get(int ObjectGroupingID)
{
ObjectGrouping objectGrouping;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader iReader = new DataReader(ObjectGroupingDA.Get(tc, ObjectGroupingID));
objectGrouping = this.CreateObject<ObjectGrouping>(iReader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return objectGrouping;
}
public ObjectGroupingCollection Get()
{
ObjectGroupingCollection grps;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader iReader = new DataReader(ObjectGroupingDA.Get(tc));
grps = this.CreateObject<ObjectGroupingCollection>(iReader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return grps;
}
#endregion
}
}