253 lines
6.1 KiB
C#
253 lines
6.1 KiB
C#
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 GroupService : ServiceTemplate
|
|
{
|
|
#region Constructor
|
|
|
|
public GroupService()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
private void MapObject(Grouping oGrouping, DataReader dr)
|
|
{
|
|
base.SetObjectID(oGrouping, dr.GetInt32("GroupingId").Value);
|
|
oGrouping.Name = dr.GetString("Name");
|
|
oGrouping.Description = dr.GetString("Description");
|
|
oGrouping.ObjectGroupingID = dr.GetInt32("LeaveYear", 0);
|
|
|
|
this.SetObjectState(oGrouping, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader dr)
|
|
{
|
|
Grouping oGrouping = new Grouping();
|
|
MapObject(oGrouping, dr);
|
|
return oGrouping as T;
|
|
}
|
|
|
|
#region Service Implementation
|
|
|
|
public void Save(Grouping group)
|
|
{
|
|
try
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
#region Saving data
|
|
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
if (group.IsNew)
|
|
{
|
|
int newID = GroupDA.GenID(tc);
|
|
base.SetObjectID(group, newID);
|
|
GroupDA.Insert(tc, group);
|
|
}
|
|
else
|
|
GroupDA.Update(tc, group);
|
|
|
|
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 groupID)
|
|
{
|
|
{
|
|
try
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
#region Deleting data
|
|
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
GroupDA.Delete(tc, groupID);
|
|
|
|
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 Grouping Get(int groupID)
|
|
{
|
|
Grouping group;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
#region Retrieving data
|
|
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader iReader = new DataReader(GroupDA.Get(tc, groupID));
|
|
group = this.CreateObject<Grouping>(iReader);
|
|
|
|
tc.End();
|
|
|
|
#endregion
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return group;
|
|
}
|
|
|
|
public GroupingCollection Get()
|
|
{
|
|
GroupingCollection grps;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
#region Retrieving data
|
|
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader iReader = new DataReader(GroupDA.Get(tc));
|
|
grps = this.CreateObject<GroupingCollection>(iReader);
|
|
|
|
tc.End();
|
|
|
|
#endregion
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return grps;
|
|
}
|
|
|
|
public GroupingCollection Get(bool isObjectGroup)
|
|
{
|
|
GroupingCollection grps;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
#region Retrieving data
|
|
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader iReader = new DataReader(GroupDA.Get(tc, isObjectGroup));
|
|
grps = this.CreateObject<GroupingCollection>(iReader);
|
|
|
|
tc.End();
|
|
|
|
#endregion
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return grps;
|
|
}
|
|
|
|
public GroupingCollection GetByParent(int parentID, bool isObjectGroup)
|
|
{
|
|
GroupingCollection grps;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
#region Retrieving data
|
|
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader iReader = new DataReader(GroupDA.GetByParent(tc, parentID, isObjectGroup));
|
|
grps = this.CreateObject<GroupingCollection>(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
|
|
}
|
|
} |