HRM-10/HRM.DA/Service/LearningManagement/LessonProgressService.cs

148 lines
3.9 KiB
C#
Raw Normal View History

2026-11-03 13:06:00 +06:00
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 LessonProgressService : ServiceTemplate, ILessonProgressService
{
public LessonProgressService() { }
private void MapObject(LessonProgress oLessonProgress, DataReader oReader)
{
base.SetObjectID(oLessonProgress, oReader.GetInt32("LessonProgressID").Value);
oLessonProgress.UserID = oReader.GetInt32("UserID").Value;
oLessonProgress.CourseProgressID = oReader.GetInt32("CourseProgressID").Value;
oLessonProgress.LessonID = oReader.GetInt32("LessonID").Value;
oLessonProgress.LessonContentID = oReader.GetInt32("LessonContentID").Value;
oLessonProgress.CompletionPercentage = oReader.GetFloat("CompletionPercentage").Value;
oLessonProgress.StartDate = oReader.GetDateTime("StartDate").Value;
oLessonProgress.CompleteDate = oReader.GetDateTime("CompleteDate");
oLessonProgress.IsLessonComplete = oReader.GetBoolean("IsLessonComplete").Value;
oLessonProgress.LastAccessed = oReader.GetDateTime("LastAccessed");
oLessonProgress.TimeSpent = oReader.GetString("TimeSpent");
oLessonProgress.RetryCount = oReader.GetInt32("RetryCount");
this.SetObjectState(oLessonProgress, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
LessonProgress oCourseProgress = new LessonProgress();
MapObject(oCourseProgress, oReader);
return oCourseProgress as T;
}
protected LessonProgress CreateObject(DataReader oReader)
{
LessonProgress oLessonProgress = new LessonProgress();
MapObject(oLessonProgress, oReader);
return oLessonProgress;
}
#region Save
public int Save(LessonProgress oLessonProgress)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oLessonProgress.IsNew)
{
int ID = tc.GenerateID("LMS_LessonProgress", "LessonProgressID");
base.SetObjectID(oLessonProgress, ID);
LessonProgressDA.Insert(tc, oLessonProgress);
}
tc.End();
return oLessonProgress.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(TransactionContext tc, LessonProgress oLessonProgress)
{
try
{
if (oLessonProgress.IsNew)
{
int ID = tc.GenerateID("LMS_LessonProgress", "LessonProgressID");
base.SetObjectID(oLessonProgress, ID);
LessonProgressDA.Insert(tc, oLessonProgress);
}
return oLessonProgress.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void UpdateProgress(TransactionContext tc, LessonProgress oLessonProgress)
{
try
{
LessonProgressDA.Update(tc, oLessonProgress);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
#region GET
public List<LessonProgress> GetByProgressID(int courseProgressID)
{
List<LessonProgress> oLessonProgress = new List<LessonProgress>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LessonProgressDA.GetByProgressID(tc, courseProgressID));
oLessonProgress = this.CreateObjects<LessonProgress>(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 oLessonProgress;
}
#endregion
}
}