302 lines
8.0 KiB
C#
302 lines
8.0 KiB
C#
|
using System;
|
|||
|
using Ease.Core.Model;
|
|||
|
using Ease.Core.DataAccess;
|
|||
|
using Ease.Core.Utility;
|
|||
|
using System.Collections.Generic;
|
|||
|
using HRM.BO;
|
|||
|
using System.Data;
|
|||
|
using Ease.Core;
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
|
|||
|
namespace HRM.DA
|
|||
|
{
|
|||
|
#region Training Service
|
|||
|
|
|||
|
class TrainingDepartmentService : ServiceTemplate
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
|
|||
|
private void MapObject(TrainingDepartment oTrainingDepartment, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oTrainingDepartment, (oReader.GetInt32("TrainDepartmentID").Value));
|
|||
|
oTrainingDepartment.TrainingNeedAnalysisID = oReader.GetInt32("TrainingNeedAnalysisID", 0);
|
|||
|
oTrainingDepartment.DepartmentID = oReader.GetInt32("DepartmentID", 0);
|
|||
|
oTrainingDepartment.Remarks = oReader.GetString("Remarks");
|
|||
|
|
|||
|
this.SetObjectState(oTrainingDepartment, Ease.Core.ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
TrainingDepartment oTrainingDepartmentg = new TrainingDepartment();
|
|||
|
MapObject(oTrainingDepartmentg, oReader);
|
|||
|
return oTrainingDepartmentg as T;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Implementation of ITrainingDepartmentService
|
|||
|
|
|||
|
#region Get TrainingDepartment
|
|||
|
|
|||
|
public TrainingDepartment Get(int TrainingDepartmentID)
|
|||
|
{
|
|||
|
TrainingDepartment oTrainingDepartment = null;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
#region Retrieving data
|
|||
|
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader oreader = new DataReader(TrainingDepartmentDA.Get(tc, TrainingDepartmentID));
|
|||
|
oreader.Read();
|
|||
|
oTrainingDepartment = CreateObject<TrainingDepartment>(oreader);
|
|||
|
|
|||
|
tc.End();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return oTrainingDepartment;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Get List<TrainingDepartment>
|
|||
|
|
|||
|
public List<TrainingDepartment> Get()
|
|||
|
{
|
|||
|
List<TrainingDepartment> TrainingDepartments = null;
|
|||
|
;
|
|||
|
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
#region Retrieving data
|
|||
|
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader oreader = new DataReader(TrainingDepartmentDA.Get(tc));
|
|||
|
TrainingDepartments = CreateObjects<TrainingDepartment>(oreader);
|
|||
|
|
|||
|
tc.End();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return TrainingDepartments;
|
|||
|
}
|
|||
|
|
|||
|
public List<TrainingDepartment> GetByTrainingNeedAnalysisID(int TrainingNeedAnalysisID)
|
|||
|
{
|
|||
|
List<TrainingDepartment> TrainingDepartments = null;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
#region Retrieving data
|
|||
|
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader oreader =
|
|||
|
new DataReader(TrainingDepartmentDA.GetByTrainingNeedAnalysisID(tc, TrainingNeedAnalysisID));
|
|||
|
TrainingDepartments = CreateObjects<TrainingDepartment>(oreader);
|
|||
|
|
|||
|
tc.End();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return TrainingDepartments;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Insert TrainingDepartment
|
|||
|
|
|||
|
public int Save(TrainingDepartment oTrainingDepartment)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
#region Saving data
|
|||
|
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
|
|||
|
|
|||
|
if (oTrainingDepartment.IsNew)
|
|||
|
{
|
|||
|
int newID = tc.GenerateID("TrainingDepartment", "TrainDepartmentID");
|
|||
|
base.SetObjectID(oTrainingDepartment, (newID));
|
|||
|
|
|||
|
|
|||
|
TrainingDepartmentDA.Insert(tc, oTrainingDepartment);
|
|||
|
}
|
|||
|
else
|
|||
|
TrainingDepartmentDA.Update(tc, oTrainingDepartment);
|
|||
|
|
|||
|
|
|||
|
tc.End();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
//throw new ServiceException(e.Message, e);
|
|||
|
throw new Exception(e.Message, e);
|
|||
|
}
|
|||
|
|
|||
|
return oTrainingDepartment.ID;
|
|||
|
}
|
|||
|
|
|||
|
public int Save(TransactionContext tc, TrainingDepartment oTrainingDepartment)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
#region Saving data
|
|||
|
|
|||
|
if (oTrainingDepartment.IsNew)
|
|||
|
{
|
|||
|
int newID = tc.GenerateID("TrainingDepartment", "TrainDepartmentID");
|
|||
|
base.SetObjectID(oTrainingDepartment, (newID));
|
|||
|
TrainingDepartmentDA.Insert(tc, oTrainingDepartment);
|
|||
|
}
|
|||
|
else
|
|||
|
TrainingDepartmentDA.Update(tc, oTrainingDepartment);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
//throw new ServiceException(e.Message, e);
|
|||
|
throw new Exception(e.Message, e);
|
|||
|
}
|
|||
|
|
|||
|
return oTrainingDepartment.ID;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Delete
|
|||
|
|
|||
|
public void Delete(int id)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
#region Deleting data
|
|||
|
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
TrainingDepartmentDA.Delete(tc, id);
|
|||
|
|
|||
|
tc.End();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
public bool DoesTrainingDepartmentExists(int TrainingDepartmentID)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
bool result = false;
|
|||
|
result = TrainingDepartmentDA.DoesTrainingDepartmentExists(tc, TrainingDepartmentID);
|
|||
|
tc.End();
|
|||
|
return result;
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
throw new Exception(e.Message, e);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|