205 lines
6.2 KiB
C#
205 lines
6.2 KiB
C#
using HRM.BO;
|
|
using HRM.DA;
|
|
using Ease.Core.DataAccess;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.Utility;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using Microsoft.AspNetCore.Http;
|
|
using NPOI.SS.Formula.Functions;
|
|
using System.Collections;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
public class CompetencyService : ServiceTemplate, ICompetencyService
|
|
{
|
|
public CompetencyService()
|
|
{
|
|
}
|
|
|
|
private void MapObject(Competency oCompetency, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oCompetency, oReader.GetInt32("CompetencyID").Value);
|
|
oCompetency.Code = oReader.GetString("code");
|
|
oCompetency.Name = oReader.GetString("description");
|
|
oCompetency.Tier = oReader.GetInt32("Tire").Value;
|
|
oCompetency.ParentID = oReader.GetInt32("parentID");
|
|
//oCompetency.ParentsID = oReader.GetString("parentsID");
|
|
oCompetency.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
//oCompetency.PMPYearID = oReader.GetInt32("PMPYearID").Value;
|
|
//oCompetency.Title = oReader.GetString("Title");
|
|
oCompetency.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|
oCompetency.CreatedDate = oReader.GetDateTime("CreationDate") == null
|
|
? DateTime.Today
|
|
: oReader.GetDateTime("CreationDate").Value;
|
|
oCompetency.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|
oCompetency.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(oCompetency, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
Competency oCompetency = new Competency();
|
|
MapObject(oCompetency, oReader);
|
|
return oCompetency as T;
|
|
}
|
|
|
|
protected Competency CreateObject(DataReader oReader)
|
|
{
|
|
Competency oCompetency = new Competency();
|
|
MapObject(oCompetency, oReader);
|
|
return oCompetency;
|
|
}
|
|
|
|
public int Save(Competency item)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (item.IsNew)
|
|
{
|
|
int id = tc.GenerateID("Competency", "CompetencyID");
|
|
base.SetObjectID(item, id);
|
|
//int sequenceId = tc.GenerateID("Competency", "SequenceNO");
|
|
//item.Sequence = sequenceId;
|
|
|
|
CompetencyDA.Insert(tc, item);
|
|
}
|
|
else
|
|
{
|
|
CompetencyDA.Update(tc, item);
|
|
}
|
|
|
|
tc.End();
|
|
return item.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);
|
|
CompetencyDA.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 List<Competency> Get(EnumStatus status, int payrollTypeID)
|
|
{
|
|
List<Competency> competencys = new List<Competency>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(CompetencyDA.Get(tc, status, payrollTypeID));
|
|
competencys = this.CreateObjects<Competency>(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 competencys;
|
|
}
|
|
|
|
public Competency Get(int id)
|
|
{
|
|
Competency oCompetency = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(CompetencyDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oCompetency = this.CreateObject<Competency>(oreader);
|
|
}
|
|
|
|
oreader.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return oCompetency;
|
|
}
|
|
public string GetNextCode(int tier, int parentid)
|
|
{
|
|
TransactionContext tc = null;
|
|
string code = "";
|
|
string parentCode = "";
|
|
try
|
|
{
|
|
if (parentid != -1)
|
|
{
|
|
Competency parent = this.Get((int)parentid);
|
|
if (parent != null)
|
|
parentCode = parent.Code;
|
|
}
|
|
|
|
tc = TransactionContext.Begin();
|
|
code = GlobalFunctionService.GetMaxCodeofTree(tc, "Competency", "codeautogenerate", "Competency",
|
|
"Code", "CompetencyID", "PARENTID", parentCode, tier);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return code;
|
|
}
|
|
}
|
|
}
|