274 lines
7.8 KiB
C#
274 lines
7.8 KiB
C#
|
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
|
|||
|
{
|
|||
|
#region Class AchievementService
|
|||
|
[Serializable]
|
|||
|
public class AchievementService : ServiceTemplate, IAchievementService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
Cache _cache = new Cache(typeof(Achievement));
|
|||
|
#endregion
|
|||
|
|
|||
|
#region constructor
|
|||
|
public AchievementService() { }
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Object
|
|||
|
|
|||
|
private void MapObject(Achievement oAchievement, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oAchievement, oReader.GetID("ACHIEVEMENTID"));
|
|||
|
oAchievement.Code = oReader.GetString("CODE");
|
|||
|
oAchievement.Description = oReader.GetString("DESCRIPTION");
|
|||
|
oAchievement.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|||
|
oAchievement.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|||
|
oAchievement.CreatedBy = oReader.GetID("CreatedBy");
|
|||
|
oAchievement.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|||
|
oAchievement.ModifiedBy = oReader.GetID("ModifiedBy");
|
|||
|
oAchievement.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
|
|||
|
this.SetObjectState(oAchievement, Ease.CoreV35.ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
Achievement oAchievement = new Achievement();
|
|||
|
MapObject(oAchievement, oReader);
|
|||
|
return oAchievement as T;
|
|||
|
}
|
|||
|
|
|||
|
protected Achievement CreateObject(DataReader oReader)
|
|||
|
{
|
|||
|
Achievement oAchievement = new Achievement();
|
|||
|
MapObject(oAchievement, oReader);
|
|||
|
return oAchievement;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Service implementation
|
|||
|
|
|||
|
public Achievement Get(ID id)
|
|||
|
{
|
|||
|
Achievement oAchievement = new Achievement();
|
|||
|
#region Cache Header
|
|||
|
oAchievement = _cache["Get", id] as Achievement;
|
|||
|
if (oAchievement != null)
|
|||
|
return oAchievement;
|
|||
|
#endregion
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(AchievementDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oAchievement = this.CreateObject<Achievement>(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(oAchievement, "Get", id);
|
|||
|
#endregion
|
|||
|
return oAchievement;
|
|||
|
}
|
|||
|
|
|||
|
public Achievement Get(string sCode)
|
|||
|
{
|
|||
|
Achievement oAchievement = new Achievement();
|
|||
|
#region Cache Header
|
|||
|
oAchievement = _cache["Get", sCode] as Achievement;
|
|||
|
if (oAchievement != null)
|
|||
|
return oAchievement;
|
|||
|
#endregion
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(AchievementDA.Get(tc, sCode));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oAchievement = this.CreateObject<Achievement>(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(oAchievement, "Get", sCode);
|
|||
|
#endregion
|
|||
|
return oAchievement;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<Achievement> Get()
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<Achievement> relations = _cache["Get"] as ObjectsTemplate<Achievement>;
|
|||
|
if (relations != null)
|
|||
|
return relations;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(AchievementDA.Get(tc));
|
|||
|
relations = this.CreateObjects<Achievement>(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(relations, "Get");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return relations;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<Achievement> Get(EnumStatus status)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<Achievement> relations = _cache["Get"] as ObjectsTemplate<Achievement>;
|
|||
|
if (relations != null)
|
|||
|
return relations;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(AchievementDA.Get(tc, status));
|
|||
|
relations = this.CreateObjects<Achievement>(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(relations, "Get", status);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return relations;
|
|||
|
}
|
|||
|
|
|||
|
public ID Save(Achievement oAchievement)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (oAchievement.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("ACHIEVEMENT", "ACHIEVEMENTID");
|
|||
|
base.SetObjectID(oAchievement, ID.FromInteger(id));
|
|||
|
AchievementDA.Insert(tc, oAchievement);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
AchievementDA.Update(tc, oAchievement);
|
|||
|
}
|
|||
|
tc.End();
|
|||
|
return oAchievement.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);
|
|||
|
AchievementDA.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
|
|||
|
}
|