CEL_Payroll/Payroll.Service/Organogram/Service/SkillService.cs

290 lines
8.0 KiB
C#
Raw Permalink 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
{
#region Skill Service
[Serializable]
public class SkillService : ServiceTemplate,ISkillService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(Skill));
#endregion
public SkillService()
{ }
private void MapObject(Skill oSkill, DataReader oReader)
{
base.SetObjectID(oSkill, oReader.GetID("SkillID"));
oSkill.Code = oReader.GetString("Code");
oSkill.Name = oReader.GetString("Name");
oSkill.ParentID = oReader.GetID("ParentID");
oSkill.Tier = oReader.GetInt32("Tire").Value;
oSkill.Sequence = oReader.GetInt32("SequenceNO").Value;
oSkill.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oSkill.CreatedBy = oReader.GetID("CreatedBy");
oSkill.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oSkill.ModifiedBy = oReader.GetID("ModifiedBy");
oSkill.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oSkill, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Skill oSkill = new Skill();
MapObject(oSkill, oReader);
return oSkill as T;
}
protected Skill CreateObject(DataReader oReader)
{
Skill oSkill = new Skill();
MapObject(oSkill, oReader);
return oSkill;
}
#region Service implementation
public ID Save(Skill oSkill)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oSkill.IsNew)
{
int id = tc.GenerateID("Skill", "SkillID");
base.SetObjectID(oSkill, ID.FromInteger(id));
SkillDA.Insert(tc, oSkill);
}
else
{
SkillDA.Update(tc, oSkill);
}
tc.End();
return oSkill.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);
SkillDA.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 Skill Get(ID id)
{
Skill oSkill = new Skill();
#region Cache Header
oSkill = _cache["Get", id] as Skill;
if (oSkill != null)
return oSkill;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(SkillDA.Get(tc, id));
if (oreader.Read())
{
oSkill = this.CreateObject<Skill>(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(oSkill, "Get", id);
#endregion
return oSkill;
}
public ObjectsTemplate<Skill> Get()
{
#region Cache Header
ObjectsTemplate<Skill> oSkill = _cache["Get"] as ObjectsTemplate<Skill>;
if (oSkill != null)
return oSkill;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SkillDA.Get(tc));
oSkill = this.CreateObjects<Skill>(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(oSkill, "Get");
#endregion
return oSkill;
}
public ObjectsTemplate<Skill> GetParents(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Skill> skills = _cache["GetParents", status] as ObjectsTemplate<Skill>;
if (skills != null)
return skills;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SkillDA.GetParents(tc, status));
skills = this.CreateObjects<Skill>(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(skills, "GetParents", status);
#endregion
return skills;
}
public ObjectsTemplate<Skill> GetChilds(ID parentID)
{
#region Cache Header
ObjectsTemplate<Skill> skills = _cache["GetChilds"] as ObjectsTemplate<Skill>;
if (skills != null)
return skills;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SkillDA.GetChilds(tc, parentID));
skills = this.CreateObjects<Skill>(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(skills, "GetChilds");
#endregion
return skills;
}
public bool IsExists(string Code)
{
TransactionContext tc = null;
bool isExists = false;
try
{
tc = TransactionContext.Begin(true);
isExists = SkillDA.IsExists(tc, Code);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to get Skill due to " + e.Message, e);
#endregion
}
return isExists;
}
#endregion
}
#endregion
}