CEL_Payroll/Payroll.Service/HRBasic/Service/DisciplineService.cs

435 lines
13 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;
using Payroll.Service.HRBasic.DA;
namespace Payroll.Service
{
#region class DisciplineService
[Serializable]
public class DisciplineService : ServiceTemplate, IDisciplineService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(Discipline));
#endregion
#region constructor
public DisciplineService()
{ }
#endregion
#region Object
private void MapObject(Discipline oDiscipline, DataReader oReader)
{
base.SetObjectID(oDiscipline, oReader.GetID("DISCIPLINEID"));
oDiscipline.Code = oReader.GetString("CODE");
oDiscipline.Description = oReader.GetString("DESCRIPTION");
oDiscipline.EducationLevelID = oReader.GetID("EDUCATIONLEVELID").IsUnassigned ? ID.FromInteger(1) : oReader.GetID("EDUCATIONLEVELID");
oDiscipline.Sequence = oReader.GetInt32("SequenceNo").Value;
oDiscipline.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oDiscipline.CreatedBy = oReader.GetID("CreatedBy");
oDiscipline.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oDiscipline.ModifiedBy = oReader.GetID("ModifiedBy");
oDiscipline.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oDiscipline, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Discipline oDiscipline = new Discipline();
MapObject(oDiscipline, oReader);
return oDiscipline as T;
}
protected Discipline CreateObject(DataReader oReader)
{
Discipline oDiscipline = new Discipline();
MapObject(oDiscipline, oReader);
return oDiscipline;
}
private void MapDisLevelObject(Discipline.DisciplineLevel oDisLevel, DataReader oReader)
{
base.SetObjectID(oDisLevel, oReader.GetID("DISCIPLINELEVELID"));
oDisLevel.DiscilineID = oReader.GetID("DISCIPLINEID");
oDisLevel.LevelID = oReader.GetID("LEVELID");
this.SetObjectState(oDisLevel, Ease.CoreV35.ObjectState.Saved);
}
protected ObjectsTemplate<Discipline.DisciplineLevel> CreateDisLevelObjects(DataReader oReader)
{
ObjectsTemplate<Discipline.DisciplineLevel> oDisciplineLevels = new ObjectsTemplate<Discipline.DisciplineLevel>();
while(oReader.Read())
{
Discipline.DisciplineLevel oDisLevel=new Discipline.DisciplineLevel();
MapDisLevelObject(oDisLevel, oReader);
oDisciplineLevels.Add(oDisLevel);
}
return oDisciplineLevels;
}
#endregion
#region Service implementation
public Discipline Get(ID id)
{
Discipline oDiscipline = new Discipline();
#region Cache Header
oDiscipline = _cache["Get", id] as Discipline;
if (oDiscipline != null)
return oDiscipline;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DisciplineDA.Get(tc, id));
if (oreader.Read())
{
oDiscipline = this.CreateObject<Discipline>(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(oDiscipline, "Get", id);
#endregion
return oDiscipline;
}
public Discipline Get(string sCode)
{
Discipline oDiscipline = new Discipline();
#region Cache Header
oDiscipline = _cache["Get", sCode] as Discipline;
if (oDiscipline != null)
return oDiscipline;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DisciplineDA.Get(tc, sCode));
if (oreader.Read())
{
oDiscipline = this.CreateObject<Discipline>(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(oDiscipline, "Get", sCode);
#endregion
return oDiscipline;
}
public ObjectsTemplate<Discipline> Get()
{
#region Cache Header
ObjectsTemplate<Discipline> disciplines = _cache["Get"] as ObjectsTemplate<Discipline>;
if (disciplines != null)
return disciplines;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DisciplineDA.Get(tc));
disciplines = this.CreateObjects<Discipline>(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(disciplines, "Get");
#endregion
return disciplines;
}
public ObjectsTemplate<Discipline> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Discipline> disciplines = _cache["Get"] as ObjectsTemplate<Discipline>;
if (disciplines != null)
return disciplines;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DisciplineDA.Get(tc, status));
disciplines = this.CreateObjects<Discipline>(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(disciplines, "Get", status);
#endregion
return disciplines;
}
public ObjectsTemplate<Discipline> GetByEducationLevel(ID levelID)
{
#region Cache Header
ObjectsTemplate<Discipline> disciplines = _cache["GetByEducationLevel"] as ObjectsTemplate<Discipline>;
if (disciplines != null)
return disciplines;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DisciplineDA.GetByEducationLevel(tc, levelID.Integer));
disciplines = this.CreateObjects<Discipline>(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(disciplines, "GetByEducationLevel", levelID);
#endregion
return disciplines;
}
public ObjectsTemplate<Discipline.DisciplineLevel> GetDisplineByDID(ID DisID)
{
#region Cache Header
ObjectsTemplate<Discipline.DisciplineLevel> disciplines = _cache["GetDisplineByDID"] as ObjectsTemplate<Discipline.DisciplineLevel>;
if (disciplines != null)
return disciplines;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DisciplineDA.GetDisplineByDID(tc, DisID));
disciplines = this.CreateDisLevelObjects(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(disciplines, "GetDisplineByDID", DisID);
#endregion
return disciplines;
}
public ObjectsTemplate<Discipline.DisciplineLevel> GetDisByEducationLevel(ID LevelID)
{
#region Cache Header
ObjectsTemplate<Discipline.DisciplineLevel> disciplines = _cache["GetDisByEducationLevel"] as ObjectsTemplate<Discipline.DisciplineLevel>;
if (disciplines != null)
return disciplines;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(DisciplineDA.GetDisByEducationLevel(tc, LevelID));
disciplines = this.CreateDisLevelObjects(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(disciplines, "GetDisByEducationLevel", LevelID);
#endregion
return disciplines;
}
public ID Save(Discipline oDiscipline)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oDiscipline.IsNew)
{
int id = tc.GenerateID("DISCIPLINE", "DISCIPLINEID");
base.SetObjectID(oDiscipline, ID.FromInteger(id));
DisciplineDA.Insert(tc, oDiscipline);
}
else
{
DisciplineDA.Update(tc, oDiscipline);
DisciplineDA.DeleteByDisID(tc, oDiscipline.ID.Integer);
}
foreach (Discipline.DisciplineLevel disciplineLevel in oDiscipline.DisciplineLevels)
{
int id = tc.GenerateID("DisciplineLevel", "DisciplineLevelID");
disciplineLevel.DiscilineID = oDiscipline.ID;
base.SetObjectID(disciplineLevel, ID.FromInteger(id));
DisciplineDA.Insert(tc, disciplineLevel);
}
tc.End();
return oDiscipline.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);
DisciplineDA.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
}