From e63a596e77d69786530860c8eec80193b59494ec Mon Sep 17 00:00:00 2001 From: sherif-olaboye <123654949+sherif-olaboye@users.noreply.github.com> Date: Thu, 31 Jul 2025 16:02:11 +0100 Subject: [PATCH] TD-5669 Learners enrolling onto a retiring self assessment --- .../SelfAssessmentDataService.cs | 13 +++++ .../Models/SelfAssessments/SelfAssessment.cs | 4 +- .../LearningPortalController/Available.cs | 35 ++++++++++++ .../Services/SelfAssessmentService.cs | 5 ++ .../Available/RetirementViewModel.cs | 25 +++++++++ .../Available/ConfirmRetirement.cshtml | 54 +++++++++++++++++++ 6 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 DigitalLearningSolutions.Web/ViewModels/LearningPortal/Available/RetirementViewModel.cs create mode 100644 DigitalLearningSolutions.Web/Views/LearningPortal/Available/ConfirmRetirement.cshtml diff --git a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs index 324a1050a7..e002025532 100644 --- a/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs @@ -16,6 +16,7 @@ public interface ISelfAssessmentDataService { //Self Assessments string? GetSelfAssessmentNameById(int selfAssessmentId); + SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId); // CompetencyDataService IEnumerable GetCompetencyIdsForSelfAssessment(int selfAssessmentId); @@ -204,6 +205,18 @@ FROM SelfAssessments return name; } + public SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId) + { + var date = connection.QueryFirstOrDefault( + @"SELECT Id,Name,[RetirementDate] + FROM SelfAssessments + WHERE ID = @selfAssessmentId" + , + new { selfAssessmentId } + ); + return date; + } + public (IEnumerable, int) GetSelfAssessmentDelegates(string searchString, int offSet, int itemsPerPage, string sortBy, string sortDirection, int? selfAssessmentId, int centreId, bool? isDelegateActive, bool? removed, bool? submitted, bool? signedOff) { diff --git a/DigitalLearningSolutions.Data/Models/SelfAssessments/SelfAssessment.cs b/DigitalLearningSolutions.Data/Models/SelfAssessments/SelfAssessment.cs index 1beabfb672..59aae71ca6 100644 --- a/DigitalLearningSolutions.Data/Models/SelfAssessments/SelfAssessment.cs +++ b/DigitalLearningSolutions.Data/Models/SelfAssessments/SelfAssessment.cs @@ -1,4 +1,5 @@ -namespace DigitalLearningSolutions.Data.Models.SelfAssessments +using System; +namespace DigitalLearningSolutions.Data.Models.SelfAssessments { public class SelfAssessment : CurrentLearningItem { @@ -11,6 +12,7 @@ public class SelfAssessment : CurrentLearningItem public string? ManageOptionalCompetenciesPrompt { get; set; } public string? QuestionLabel { get; set; } public string? DescriptionLabel { get; set; } + public DateTime? RetirementDate { get; set; } } } diff --git a/DigitalLearningSolutions.Web/Controllers/LearningPortalController/Available.cs b/DigitalLearningSolutions.Web/Controllers/LearningPortalController/Available.cs index 6e8a5a3d90..b9e16e7ac6 100644 --- a/DigitalLearningSolutions.Web/Controllers/LearningPortalController/Available.cs +++ b/DigitalLearningSolutions.Web/Controllers/LearningPortalController/Available.cs @@ -4,8 +4,10 @@ using DigitalLearningSolutions.Data.Models.SearchSortFilterPaginate; using DigitalLearningSolutions.Web.Attributes; using DigitalLearningSolutions.Web.Helpers; + using DigitalLearningSolutions.Web.Services; using DigitalLearningSolutions.Web.ViewModels.LearningPortal.Available; using Microsoft.AspNetCore.Mvc; + using System; using System.Linq; public partial class LearningPortalController @@ -58,8 +60,41 @@ public IActionResult AllAvailableItems() public IActionResult EnrolOnSelfAssessment(int selfAssessmentId) { + var selfAssessment = selfAssessmentService.GetSelfAssessmentRetirementDateById(selfAssessmentId); + if(CheckRetirementDate(selfAssessment.RetirementDate)) return RedirectToAction("ConfirmRetirement", new { selfAssessmentId }); courseService.EnrolOnSelfAssessment(selfAssessmentId, User.GetUserIdKnownNotNull(), User.GetCentreIdKnownNotNull()); return RedirectToAction("SelfAssessment", new { selfAssessmentId }); } + + [Route("/LearningPortal/Retirement/{selfAssessmentId:int}/confirm")] + public IActionResult ConfirmRetirement(int selfAssessmentId) + { + var selfAssessment = selfAssessmentService.GetSelfAssessmentRetirementDateById(selfAssessmentId); + var model = new RetirementViewModel(selfAssessmentId, selfAssessment.RetirementDate, selfAssessment.Name); + return View("Available/ConfirmRetirement", model); + } + [HttpPost] + [Route("/LearningPortal/Retirement/{selfAssessmentId:int}/confirm")] + public IActionResult ConfirmRetirement(RetirementViewModel retirementViewModel) + { + if (!ModelState.IsValid && !retirementViewModel.ActionConfirmed) + { + var selfAssessment = selfAssessmentService.GetSelfAssessmentRetirementDateById(retirementViewModel.SelfAssessmentId); + var model = new RetirementViewModel(retirementViewModel.SelfAssessmentId , selfAssessment.RetirementDate, selfAssessment.Name); + return View("Available/ConfirmRetirement", model); + } + var date = selfAssessmentService.GetSelfAssessmentRetirementDateById(retirementViewModel.SelfAssessmentId); + courseService.EnrolOnSelfAssessment(retirementViewModel.SelfAssessmentId, User.GetUserIdKnownNotNull(), User.GetCentreIdKnownNotNull()); + return RedirectToAction("SelfAssessment", new { retirementViewModel.SelfAssessmentId }); + } + private bool CheckRetirementDate(DateTime? date) + { + if (date == null) + return false; + + DateTime twoWeeksbeforeRetirementdate = DateTime.Today.AddDays(14); + DateTime today = DateTime.Today; + return (date >= today && date <= twoWeeksbeforeRetirementdate); + } } } diff --git a/DigitalLearningSolutions.Web/Services/SelfAssessmentService.cs b/DigitalLearningSolutions.Web/Services/SelfAssessmentService.cs index c9a50014fa..0a9367b83b 100644 --- a/DigitalLearningSolutions.Web/Services/SelfAssessmentService.cs +++ b/DigitalLearningSolutions.Web/Services/SelfAssessmentService.cs @@ -162,6 +162,7 @@ public IEnumerable GetSelfAssessmentResultswithSupervisorV int competencyId ); void RemoveReviewCandidateAssessmentOptionalCompetencies(int id); + SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId); } public class SelfAssessmentService : ISelfAssessmentService @@ -610,5 +611,9 @@ public void RemoveReviewCandidateAssessmentOptionalCompetencies(int id) { selfAssessmentDataService.RemoveReviewCandidateAssessmentOptionalCompetencies(id); } + public SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId) + { + return selfAssessmentDataService.GetSelfAssessmentRetirementDateById(selfAssessmentId); + } } } diff --git a/DigitalLearningSolutions.Web/ViewModels/LearningPortal/Available/RetirementViewModel.cs b/DigitalLearningSolutions.Web/ViewModels/LearningPortal/Available/RetirementViewModel.cs new file mode 100644 index 0000000000..bfbba45cb6 --- /dev/null +++ b/DigitalLearningSolutions.Web/ViewModels/LearningPortal/Available/RetirementViewModel.cs @@ -0,0 +1,25 @@ +using DigitalLearningSolutions.Web.Attributes; +using System; + +namespace DigitalLearningSolutions.Web.ViewModels.LearningPortal.Available +{ + + public class RetirementViewModel + { + public RetirementViewModel() + { + + } + public RetirementViewModel(int selfAssessmentId, DateTime? retirementDate, string name) + { + SelfAssessmentId = selfAssessmentId; + RetirementDate = retirementDate; + Name = name; + } + public string Name { get; set; } = string.Empty; + public int SelfAssessmentId { get; set; } + public DateTime? RetirementDate { get; set; } + [BooleanMustBeTrue(ErrorMessage = "Please tick the checkbox to confirm you wish to perform this action")] + public bool ActionConfirmed { get; set; } + } +} diff --git a/DigitalLearningSolutions.Web/Views/LearningPortal/Available/ConfirmRetirement.cshtml b/DigitalLearningSolutions.Web/Views/LearningPortal/Available/ConfirmRetirement.cshtml new file mode 100644 index 0000000000..7eba8f20ff --- /dev/null +++ b/DigitalLearningSolutions.Web/Views/LearningPortal/Available/ConfirmRetirement.cshtml @@ -0,0 +1,54 @@ +@using DigitalLearningSolutions.Web.ViewModels.LearningPortal.Available +@using Microsoft.Extensions.Configuration +@model RetirementViewModel; +@inject IConfiguration Configuration; +@{ + var errorHasOccurred = !ViewData.ModelState.IsValid; + ViewData["Application"] = "Learning Portal"; + ViewData["Title"] = "Retirement Confirmation"; + ViewData["HeaderPath"] = $"{Configuration["AppRootPath"]}/LearningPortal/Retirement"; + ViewData["HeaderPathName"] = "Learning Portal"; +} + +@section NavMenuItems { + +} +
+
+
+ @if (errorHasOccurred) + { + + } +

Confirm Retirement

+

You are about to enrol on a retiring @Model.Name self-assessment.

+

Retirement date: @Model.RetirementDate?.ToString("dd MMMM yyyy")

+

After this date, the @Model.Name self-assessment will no longer be accessible.

+ +

Please consider:

+
    +
  • you may have limited time to complete the self-assessment
  • + + +
  • if you do not complete it before the retirement date, your progress may not be saved
  • +
+

To continue, you must acknowledge that you understand the self-assessment is retiring and still wish to enrol.

+ + +

+ +

+ + + Cancel + + @Html.HiddenFor(m => m.SelfAssessmentId) + @Html.HiddenFor(m => m.RetirementDate) +
+
+
+