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

177 lines
4.5 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 CourseProgressService : ServiceTemplate, ICourseProgressService
{
public CourseProgressService() { }
private void MapObject(CourseProgres oCourseProgress, DataReader oReader)
{
base.SetObjectID(oCourseProgress, oReader.GetInt32("CourseProgressID").Value);
oCourseProgress.UserID = oReader.GetInt32("UserID").Value;
oCourseProgress.CourseID = oReader.GetInt32("CourseID").Value;
oCourseProgress.EnrollmentID = oReader.GetInt32("EnrollmentID").Value;
oCourseProgress.CompletionPercentage = oReader.GetFloat("CompletionPercentage").Value;
oCourseProgress.StartDate = oReader.GetDateTime("StartDate").Value;
oCourseProgress.EndDate = oReader.GetDateTime("EndDate");
oCourseProgress.IsCourseComplete = oReader.GetBoolean("IsCourseComplete").Value;
oCourseProgress.LastActivityDate = oReader.GetDateTime("LastActivityDate");
this.SetObjectState(oCourseProgress, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
CourseProgres oCourseProgress = new CourseProgres();
MapObject(oCourseProgress, oReader);
return oCourseProgress as T;
}
protected CourseProgres CreateObject(DataReader oReader)
{
CourseProgres oCourseProgress = new CourseProgres();
MapObject(oCourseProgress, oReader);
return oCourseProgress;
}
#region Save
public int Save(CourseProgres oCourseProgress)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oCourseProgress.IsNew)
{
int ID = tc.GenerateID("LMS_CourseProgress", "CourseProgressID");
base.SetObjectID(oCourseProgress, ID);
CourseProgressDA.Insert(tc, oCourseProgress);
}
tc.End();
return oCourseProgress.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public CourseProgres Save(TransactionContext tc, CourseProgres oCourseProgress)
{
CourseProgres newCourseProgres = null;
try
{
if (oCourseProgress.IsNew)
{
int ID = tc.GenerateID("LMS_CourseProgress", "CourseProgressID");
base.SetObjectID(oCourseProgress, ID);
CourseProgressDA.Insert(tc, oCourseProgress);
}
newCourseProgres = Get(tc, oCourseProgress.ID);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return newCourseProgres;
}
#endregion
#region UPDATE
public CourseProgres UpdateCompletionRate(TransactionContext tc, CourseProgres oCourseProgress)
{
CourseProgres newCourseProgres = null;
try
{
CourseProgressDA.UpdateCompletionRate(tc, oCourseProgress);
newCourseProgres = Get(tc, oCourseProgress.ID);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return newCourseProgres;
}
#endregion
#region Get For Enrollement
public CourseProgres Get(TransactionContext tc, int ID)
{
CourseProgres oCourseProgres = null;
try
{
DataReader oreader = new DataReader(CourseProgressDA.Get(tc, ID));
if (oreader.Read())
{
oCourseProgres = this.CreateObject<CourseProgres>(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 oCourseProgres;
}
public CourseProgres GetForEnrollement(TransactionContext tc ,int courseID, int enrollmentID, int UserID)
{
CourseProgres oCourseProgress = null;
try
{
DataReader oreader = new DataReader(CourseProgressDA.Get(tc, courseID, enrollmentID, UserID));
if (oreader.Read())
{
oCourseProgress = this.CreateObject<CourseProgres>(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 oCourseProgress;
}
#endregion
}
}