Skip to content

Commit cadb115

Browse files
authored
Merge pull request #3339 from TechnologyEnhancedLearning/Develop/Features/TD-5669-Learnersenrollingontoaretiringselfassessment
TD-5669 Learners enrolling onto a retiring self assessment
2 parents 040b6af + 23f7100 commit cadb115

File tree

6 files changed

+133
-0
lines changed

6 files changed

+133
-0
lines changed

DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public interface ISelfAssessmentDataService
1616
{
1717
//Self Assessments
1818
string? GetSelfAssessmentNameById(int selfAssessmentId);
19+
SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId);
1920

2021
// CompetencyDataService
2122
IEnumerable<int> GetCompetencyIdsForSelfAssessment(int selfAssessmentId);
@@ -204,6 +205,18 @@ FROM SelfAssessments
204205
return name;
205206
}
206207

208+
public SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId)
209+
{
210+
var date = connection.QueryFirstOrDefault<SelfAssessment>(
211+
@"SELECT Id,Name,[RetirementDate]
212+
FROM SelfAssessments
213+
WHERE ID = @selfAssessmentId"
214+
,
215+
new { selfAssessmentId }
216+
);
217+
return date;
218+
}
219+
207220
public (IEnumerable<SelfAssessmentDelegate>, int) GetSelfAssessmentDelegates(string searchString, int offSet, int itemsPerPage, string sortBy, string sortDirection,
208221
int? selfAssessmentId, int centreId, bool? isDelegateActive, bool? removed, bool? submitted, bool? signedOff)
209222
{

DigitalLearningSolutions.Data/Models/SelfAssessments/SelfAssessment.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class SelfAssessment : CurrentLearningItem
1414
public string? QuestionLabel { get; set; }
1515
public string? DescriptionLabel { get; set; }
1616
public DateTime? RetirementDate { get; set; }
17+
1718
public DateTime? EnrolmentCutoffDate { get; set; }
1819
public string? RetirementReason { get; set; }
1920

DigitalLearningSolutions.Web/Controllers/LearningPortalController/Available.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
using DigitalLearningSolutions.Data.Models.SearchSortFilterPaginate;
55
using DigitalLearningSolutions.Web.Attributes;
66
using DigitalLearningSolutions.Web.Helpers;
7+
using DigitalLearningSolutions.Web.Services;
78
using DigitalLearningSolutions.Web.ViewModels.LearningPortal.Available;
89
using Microsoft.AspNetCore.Mvc;
10+
using System;
911
using System.Linq;
1012

1113
public partial class LearningPortalController
@@ -58,8 +60,41 @@ public IActionResult AllAvailableItems()
5860

5961
public IActionResult EnrolOnSelfAssessment(int selfAssessmentId)
6062
{
63+
var selfAssessment = selfAssessmentService.GetSelfAssessmentRetirementDateById(selfAssessmentId);
64+
if(CheckRetirementDate(selfAssessment.RetirementDate)) return RedirectToAction("ConfirmRetirement", new { selfAssessmentId });
6165
courseService.EnrolOnSelfAssessment(selfAssessmentId, User.GetUserIdKnownNotNull(), User.GetCentreIdKnownNotNull());
6266
return RedirectToAction("SelfAssessment", new { selfAssessmentId });
6367
}
68+
69+
[Route("/LearningPortal/Retirement/{selfAssessmentId:int}/confirm")]
70+
public IActionResult ConfirmRetirement(int selfAssessmentId)
71+
{
72+
var selfAssessment = selfAssessmentService.GetSelfAssessmentRetirementDateById(selfAssessmentId);
73+
var model = new RetirementViewModel(selfAssessmentId, selfAssessment.RetirementDate, selfAssessment.Name);
74+
return View("Available/ConfirmRetirement", model);
75+
}
76+
[HttpPost]
77+
[Route("/LearningPortal/Retirement/{selfAssessmentId:int}/confirm")]
78+
public IActionResult ConfirmRetirement(RetirementViewModel retirementViewModel)
79+
{
80+
if (!ModelState.IsValid && !retirementViewModel.ActionConfirmed)
81+
{
82+
var selfAssessment = selfAssessmentService.GetSelfAssessmentRetirementDateById(retirementViewModel.SelfAssessmentId);
83+
var model = new RetirementViewModel(retirementViewModel.SelfAssessmentId , selfAssessment.RetirementDate, selfAssessment.Name);
84+
return View("Available/ConfirmRetirement", model);
85+
}
86+
var date = selfAssessmentService.GetSelfAssessmentRetirementDateById(retirementViewModel.SelfAssessmentId);
87+
courseService.EnrolOnSelfAssessment(retirementViewModel.SelfAssessmentId, User.GetUserIdKnownNotNull(), User.GetCentreIdKnownNotNull());
88+
return RedirectToAction("SelfAssessment", new { retirementViewModel.SelfAssessmentId });
89+
}
90+
private bool CheckRetirementDate(DateTime? date)
91+
{
92+
if (date == null)
93+
return false;
94+
95+
DateTime twoWeeksbeforeRetirementdate = DateTime.Today.AddDays(14);
96+
DateTime today = DateTime.Today;
97+
return (date >= today && date <= twoWeeksbeforeRetirementdate);
98+
}
6499
}
65100
}

DigitalLearningSolutions.Web/Services/SelfAssessmentService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public IEnumerable<SelfAssessmentResult> GetSelfAssessmentResultswithSupervisorV
162162
int competencyId
163163
);
164164
void RemoveReviewCandidateAssessmentOptionalCompetencies(int id);
165+
SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId);
165166
}
166167

167168
public class SelfAssessmentService : ISelfAssessmentService
@@ -610,5 +611,9 @@ public void RemoveReviewCandidateAssessmentOptionalCompetencies(int id)
610611
{
611612
selfAssessmentDataService.RemoveReviewCandidateAssessmentOptionalCompetencies(id);
612613
}
614+
public SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId)
615+
{
616+
return selfAssessmentDataService.GetSelfAssessmentRetirementDateById(selfAssessmentId);
617+
}
613618
}
614619
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using DigitalLearningSolutions.Web.Attributes;
2+
using System;
3+
4+
namespace DigitalLearningSolutions.Web.ViewModels.LearningPortal.Available
5+
{
6+
7+
public class RetirementViewModel
8+
{
9+
public RetirementViewModel()
10+
{
11+
12+
}
13+
public RetirementViewModel(int selfAssessmentId, DateTime? retirementDate, string name)
14+
{
15+
SelfAssessmentId = selfAssessmentId;
16+
RetirementDate = retirementDate;
17+
Name = name;
18+
}
19+
public string Name { get; set; } = string.Empty;
20+
public int SelfAssessmentId { get; set; }
21+
public DateTime? RetirementDate { get; set; }
22+
[BooleanMustBeTrue(ErrorMessage = "Please tick the checkbox to confirm you wish to perform this action")]
23+
public bool ActionConfirmed { get; set; }
24+
}
25+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
@using DigitalLearningSolutions.Web.ViewModels.LearningPortal.Available
2+
@using Microsoft.Extensions.Configuration
3+
@model RetirementViewModel;
4+
@inject IConfiguration Configuration;
5+
@{
6+
var errorHasOccurred = !ViewData.ModelState.IsValid;
7+
ViewData["Application"] = "Learning Portal";
8+
ViewData["Title"] = "Retirement Confirmation";
9+
ViewData["HeaderPath"] = $"{Configuration["AppRootPath"]}/LearningPortal/Retirement";
10+
ViewData["HeaderPathName"] = "Learning Portal";
11+
}
12+
13+
@section NavMenuItems {
14+
<partial name="Shared/_NavMenuItems" />
15+
}
16+
<form asp-controller="LearningPortal" asp-action="ConfirmRetirement" method="post">
17+
<div class="nhsuk-grid-row">
18+
<div class="nhsuk-grid-column-full word-break">
19+
@if (errorHasOccurred)
20+
{
21+
<vc:error-summary order-of-property-names="@(new[] { nameof(Model.ActionConfirmed) })" />
22+
}
23+
<h1 id="page-heading">Confirm Retirement</h1>
24+
<p class="nhsuk-body-m">You are about to enrol on a retiring <strong>@Model.Name</strong> self-assessment.</p>
25+
<p class="nhsuk-body-m"> Retirement date: <strong>@Model.RetirementDate?.ToString("dd MMMM yyyy")</strong> </p>
26+
<p class="nhsuk-body-m">After this date, the <strong>@Model.Name</strong> self-assessment will no longer be accessible.</p>
27+
28+
<p class="nhsuk-body-m">Please consider:</p>
29+
<ul class="nhsuk-list nhsuk-list--bullet">
30+
<li> you may have limited time to complete the self-assessment</li>
31+
32+
33+
<li> if you do not complete it before the retirement date, your progress may not be saved</li>
34+
</ul>
35+
<p class="nhsuk-body-m">To continue, you must acknowledge that you understand the self-assessment is retiring and still wish to enrol.</p>
36+
37+
38+
<p class="nhsuk-body-m">
39+
<vc:single-checkbox asp-for="@nameof(Model.ActionConfirmed)"
40+
label="I understand this self-assessment is retiring and still want to enrol."
41+
hint-text="" />
42+
</p>
43+
<button type="submit" class="nhsuk-button">Enrol now</button>
44+
<a class="nhsuk-button nhsuk-button--secondary"
45+
role="button"
46+
asp-controller="LearningPortal" asp-action="Available">
47+
Cancel
48+
</a>
49+
@Html.HiddenFor(m => m.SelfAssessmentId)
50+
@Html.HiddenFor(m => m.RetirementDate)
51+
</div>
52+
</div>
53+
</form>
54+

0 commit comments

Comments
 (0)