260 lines
7.0 KiB
C#
260 lines
7.0 KiB
C#
using System;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.DataAccess;
|
|
using HRM.BO;
|
|
using Ease.Core.Utility;
|
|
using System.Collections.Generic;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
public class SkillLevelService : ServiceTemplate, ISkillLevelService
|
|
{
|
|
public SkillLevelService()
|
|
{
|
|
}
|
|
|
|
private void MapObject(SkillLevel oSkilLevel, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oSkilLevel, oReader.GetInt32("SkillLevelID").Value);
|
|
oSkilLevel.Code = oReader.GetString("Code");
|
|
oSkilLevel.Name = oReader.GetString("Name");
|
|
//oSkilLevel.SkillPoint = oReader.GetInt32("SkillPoint").Value;
|
|
|
|
oSkilLevel.Sequence = oReader.GetInt32("SequenceNO").Value;
|
|
oSkilLevel.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oSkilLevel.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|
oSkilLevel.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oSkilLevel.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|
oSkilLevel.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(oSkilLevel, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
SkillLevel oSkilLevel = new SkillLevel();
|
|
MapObject(oSkilLevel, oReader);
|
|
return oSkilLevel as T;
|
|
}
|
|
|
|
|
|
#region Service implementation
|
|
|
|
public int Save(SkillLevel oSkilLevel)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oSkilLevel.IsNew)
|
|
{
|
|
int id = tc.GenerateID("SkillLevel", "SkillLevelID");
|
|
base.SetObjectID(oSkilLevel, (id));
|
|
SkillLevelDA.Insert(tc, oSkilLevel);
|
|
}
|
|
else
|
|
{
|
|
SkillLevelDA.Update(tc, oSkilLevel);
|
|
}
|
|
|
|
tc.End();
|
|
|
|
return oSkilLevel.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(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
SkillLevelDA.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 SkillLevel Get(int id)
|
|
{
|
|
SkillLevel oSkilLevel = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(SkillLevelDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oSkilLevel = this.CreateObject<SkillLevel>(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
|
|
}
|
|
|
|
return oSkilLevel;
|
|
}
|
|
|
|
public List<SkillLevel> Get()
|
|
{
|
|
List<SkillLevel> oSkilLevel = new List<SkillLevel>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(SkillLevelDA.Get(tc));
|
|
oSkilLevel = this.CreateObjects<SkillLevel>(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
|
|
}
|
|
|
|
return oSkilLevel;
|
|
}
|
|
|
|
public List<SkillLevel> Get(EnumStatus status)
|
|
{
|
|
List<SkillLevel> skills = new List<SkillLevel>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(SkillLevelDA.Get(tc, status));
|
|
skills = this.CreateObjects<SkillLevel>(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
|
|
}
|
|
|
|
|
|
return skills;
|
|
}
|
|
|
|
public bool IsExists(string Code)
|
|
{
|
|
TransactionContext tc = null;
|
|
bool isExists = false;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
isExists = SkillLevelDA.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 SkillLevel due to " + e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return isExists;
|
|
}
|
|
|
|
|
|
//public List<SkillLevel> GetChilds(int parentID)
|
|
//{
|
|
// #region Cache Header
|
|
|
|
// List<SkillLevel> skills = _cache["GetChilds"] as List<SkillLevel>;
|
|
// if (skills != null)
|
|
// return skills;
|
|
|
|
// #endregion
|
|
|
|
// TransactionContext tc = null;
|
|
// try
|
|
// {
|
|
// tc = TransactionContext.Begin();
|
|
|
|
// DataReader dr = new DataReader(SkillLevelDA.GetChilds(tc, parentID));
|
|
// skills = this.CreateObjects<SkillLevel>(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;
|
|
//}
|
|
|
|
#endregion
|
|
}
|
|
} |