204 lines
7.0 KiB
C#
204 lines
7.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Ease.CoreV35.Model;
|
|
using Payroll.BO;
|
|
using Ease.CoreV35.Caching;
|
|
using Ease.CoreV35.DataAccess;
|
|
using Payroll.BO;
|
|
using Payroll.Service.Attendence.DA;
|
|
|
|
namespace Payroll.Service.Attendence.Service
|
|
{
|
|
#region ShiftRotation Service
|
|
[Serializable]
|
|
public class ShiftRotationService : ServiceTemplate, IShiftRotationService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(ShiftRotation));
|
|
|
|
#endregion
|
|
public ShiftRotationService() { }
|
|
|
|
private void MapObject(ShiftRotation oShiftRotation, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oShiftRotation, oReader.GetID("ShiftRotationID"));
|
|
oShiftRotation.ShiftID = oReader.GetID("ShiftID");
|
|
oShiftRotation.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|
oShiftRotation.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oShiftRotation.CreatedBy = oReader.GetID("CreatedBy");
|
|
oShiftRotation.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
|
|
oShiftRotation.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
oShiftRotation.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
oShiftRotation.WorkPlanType = (EnumWorkPlanGroup)oReader.GetInt32("workGroupType");
|
|
|
|
this.SetObjectState(oShiftRotation, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
ShiftRotation oShiftRotation = new ShiftRotation();
|
|
MapObject(oShiftRotation, oReader);
|
|
return oShiftRotation as T;
|
|
}
|
|
protected ShiftRotation CreateObject(DataReader oReader)
|
|
{
|
|
ShiftRotation oShiftRotation = new ShiftRotation();
|
|
MapObject(oShiftRotation, oReader);
|
|
return oShiftRotation;
|
|
}
|
|
#region Service implementation
|
|
public ShiftRotation Get(ID id)
|
|
{
|
|
ShiftRotation oShiftRotation = new ShiftRotation();
|
|
#region Cache Header
|
|
oShiftRotation = _cache["Get", id] as ShiftRotation;
|
|
if (oShiftRotation != null)
|
|
return oShiftRotation;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(ShiftRotationDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oShiftRotation = this.CreateObject<ShiftRotation>(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
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(oShiftRotation, "Get", id);
|
|
#endregion
|
|
return oShiftRotation;
|
|
}
|
|
|
|
public ObjectsTemplate<ShiftRotation> Get(EnumWorkPlanGroup workGroup)
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<ShiftRotation> shiftRotations = _cache["Get"] as ObjectsTemplate<ShiftRotation>;
|
|
if (shiftRotations != null)
|
|
return shiftRotations;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(ShiftRotationDA.Get(tc, workGroup));
|
|
shiftRotations = this.CreateObjects<ShiftRotation>(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
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(shiftRotations, "Get");
|
|
#endregion
|
|
return shiftRotations;
|
|
}
|
|
|
|
public ID Save(ShiftRotation oShiftRotation)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oShiftRotation.IsNew)
|
|
{
|
|
int id = tc.GenerateID("ShiftRotation", "ShiftRotationID");
|
|
base.SetObjectID(oShiftRotation, ID.FromInteger(id));
|
|
int seqNo = tc.GenerateID("ShiftRotation", "SequenceNO");
|
|
oShiftRotation.Sequence = seqNo;
|
|
ShiftRotationDA.Insert(tc, oShiftRotation);
|
|
}
|
|
else
|
|
{
|
|
ShiftRotationDA.Update(tc, oShiftRotation);
|
|
}
|
|
tc.End();
|
|
return oShiftRotation.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);
|
|
ShiftRotationDA.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
|
|
}
|
|
}
|
|
|
|
public ObjectsTemplate<ShiftRotation> Get(EnumStatus status)
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<ShiftRotation> shiftRotations = _cache["Get"] as ObjectsTemplate<ShiftRotation>;
|
|
if (shiftRotations != null)
|
|
return shiftRotations;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(ShiftRotationDA.Get(tc, status));
|
|
shiftRotations = this.CreateObjects<ShiftRotation>(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
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(shiftRotations, "Get");
|
|
#endregion
|
|
return shiftRotations;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
#endregion
|
|
}
|