227 lines
5.2 KiB
C#
227 lines
5.2 KiB
C#
using Ease.Core.DataAccess;
|
|
using Ease.Core;
|
|
using Ease.Core.Model;
|
|
using HRM.BO;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Ease.Core.Utility;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
public class EnrollmentService : ServiceTemplate, IEnrollmentsService
|
|
{
|
|
public EnrollmentService() { }
|
|
|
|
private void MapObject(Enrollments oEnrollments, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oEnrollments, oReader.GetInt32("EnrollmentID").Value);
|
|
oEnrollments.UserID = oReader.GetInt32("UserID").Value;
|
|
oEnrollments.CourseID = oReader.GetInt32("CourseID").Value;
|
|
oEnrollments.EnrollDate = oReader.GetDateTime("EnrollDate").Value;
|
|
oEnrollments.IsCurrentEnroll = oReader.GetBoolean("IsCurrentEnroll").Value;
|
|
oEnrollments.NoOfEnroll = oReader.GetInt32("NoOfEnroll").Value;
|
|
this.SetObjectState(oEnrollments, ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
Enrollments oEnrollments = new Enrollments();
|
|
MapObject(oEnrollments, oReader);
|
|
return oEnrollments as T;
|
|
}
|
|
protected Enrollments CreateObject(DataReader oReader)
|
|
{
|
|
Enrollments oEnrollments = new Enrollments();
|
|
MapObject(oEnrollments, oReader);
|
|
return oEnrollments;
|
|
}
|
|
|
|
#region Save
|
|
public int Save(Enrollments oEnrollments)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oEnrollments.IsNew)
|
|
{
|
|
int ID = tc.GenerateID("LMS_Enrollments", "EnrollmentID");
|
|
base.SetObjectID(oEnrollments, ID);
|
|
EnrollmentDA.Insert(tc, oEnrollments);
|
|
}
|
|
tc.End();
|
|
return oEnrollments.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
public Enrollments Save(TransactionContext tc, Enrollments oEnrollments)
|
|
{
|
|
Enrollments oNewEnrollments = null;
|
|
try
|
|
{
|
|
if (oEnrollments.IsNew)
|
|
{
|
|
int ID = tc.GenerateID("LMS_Enrollments", "EnrollmentID");
|
|
base.SetObjectID(oEnrollments, ID);
|
|
EnrollmentDA.Insert(tc, oEnrollments);
|
|
}
|
|
oNewEnrollments = Get(tc, oEnrollments.ID);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
return oNewEnrollments;
|
|
}
|
|
#endregion
|
|
|
|
#region Update Enroll Status
|
|
public void UpdateEnrollStatus(Enrollments oEnrollments)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (!oEnrollments.IsNew)
|
|
{
|
|
EnrollmentDA.UpdateEnrollStatus(tc, oEnrollments);
|
|
}
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Get For Enrollement
|
|
public Enrollments GetForEnrollement(TransactionContext tc , int courseID, int UserID)
|
|
{
|
|
Enrollments oEnrollments = null;
|
|
try
|
|
{
|
|
DataReader oreader = new DataReader(EnrollmentDA.GetForEnrollment(tc, courseID, UserID));
|
|
if (oreader.Read())
|
|
{
|
|
oEnrollments = this.CreateObject<Enrollments>(oreader);
|
|
}
|
|
oreader.Close();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
return oEnrollments;
|
|
}
|
|
#endregion
|
|
|
|
#region GET
|
|
public Enrollments Get(TransactionContext tc, int ID)
|
|
{
|
|
Enrollments oEnrollments = null;
|
|
try
|
|
{
|
|
DataReader oreader = new DataReader(EnrollmentDA.Get(tc, ID));
|
|
if (oreader.Read())
|
|
{
|
|
oEnrollments = this.CreateObject<Enrollments>(oreader);
|
|
}
|
|
oreader.Close();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
return oEnrollments;
|
|
}
|
|
public List<Enrollments> GetAll()
|
|
{
|
|
List<Enrollments> oEnrollments = new List<Enrollments>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(EnrollmentDA.GetAll(tc));
|
|
oEnrollments = this.CreateObjects<Enrollments>(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 oEnrollments;
|
|
}
|
|
|
|
public List<Enrollments> GetByDate(DateTime fromDate, DateTime toDate)
|
|
{
|
|
List<Enrollments> oEnrollments = new List<Enrollments>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(EnrollmentDA.GetByDate(tc, fromDate, toDate));
|
|
oEnrollments = this.CreateObjects<Enrollments>(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 oEnrollments;
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
}
|