HRM-10/HRM.DA/Service/TrainingS/TrainerService.cs
Mohaimen Hasan 838b8d4480 first commit
2026-11-03 13:06:00 +06:00

221 lines
6.1 KiB
C#

using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using HRM.BO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HRM.DA
{
public class TrainerService : ServiceTemplate, ITrainerService
{
#region Constructor
public TrainerService() { }
#endregion
#region Map Object
private void MapObject(Trainer oTrainer, DataReader oReader)
{
base.SetObjectID(oTrainer, oReader.GetInt32("TrainerID").Value);
oTrainer.Code = oReader.GetString("Code");
oTrainer.Name = oReader.GetString("Name");
oTrainer.ContactNo = oReader.GetString("ContactNo", true, string.Empty);
oTrainer.EmailAddress = oReader.GetString("EmailAddress", true, string.Empty);
oTrainer.Institute = oReader.GetString("Institute", true, string.Empty);
oTrainer.Description = oReader.GetString("Description");
oTrainer.TrainerType = (EnumTrainerType)oReader.GetInt32("TrainerType");
oTrainer.EmployeeID = oReader.GetInt32("EmployeeID");
oTrainer.Rating = oReader.GetDouble("Rating");
oTrainer.EnrollDate = oReader.GetDateTime("EnrollDate").Value;
this.SetObjectState(oTrainer, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Trainer oTrainer = new Trainer();
MapObject(oTrainer, oReader);
return oTrainer as T;
}
#endregion
#region Service implementation
public Trainer Get(int ID)
{
Trainer oTrainer = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainerDA.Get(tc, ID));
if (oreader.Read())
{
oTrainer = this.CreateObject<Trainer>(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 oTrainer;
}
public List<Trainer> Get(EnumStatus status, int payrollTypeID)
{
List<Trainer> Trainers = new List<Trainer>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TrainerDA.Get(tc));
Trainers = this.CreateObjects<Trainer>(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 Trainers;
}
public List<Trainer> GetAll()
{
List<Trainer> Trainers = new List<Trainer>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TrainerDA.Get(tc));
Trainers = this.CreateObjects<Trainer>(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 Trainers;
}
public int Save(Trainer oTrainer)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oTrainer.IsNew)
{
int id = tc.GenerateID("Trainer", "TrainerID");
base.SetObjectID(oTrainer, id);
TrainerDA.Insert(tc, oTrainer);
}
else
{
TrainerDA.Update(tc, oTrainer);
}
tc.End();
return oTrainer.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);
TrainerDA.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 string GetNextCode()
{
TransactionContext tc = null;
string _code = "";
try
{
tc = TransactionContext.Begin();
_code = GlobalFunctionService.GetMaxCode(tc, "trainer", "codeautogenerate", "Trainer", "Code");
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;
}
#endregion
}
}