Skip to content

Commit f763ced

Browse files
committed
Merge branch 'DLS-Release-v1.2.3' into DLS-Release-v1.3.0
2 parents ff83f6a + 5d7d524 commit f763ced

File tree

12 files changed

+322
-17
lines changed

12 files changed

+322
-17
lines changed

DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs

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

2022
// CompetencyDataService
2123
IEnumerable<int> GetCompetencyIdsForSelfAssessment(int selfAssessmentId);
@@ -204,6 +206,67 @@ FROM SelfAssessments
204206
return name;
205207
}
206208

209+
public SelfAssessment? GetSelfAssessmentById(int selfAssessmentId)
210+
{
211+
return connection.Query<SelfAssessment?>(
212+
@"SELECT [ID]
213+
,[Name]
214+
,[Description]
215+
,[IncludesSignposting]
216+
,[BrandID]
217+
,[CreatedDate]
218+
,[CreatedByCentreID]
219+
,[CreatedByAdminID]
220+
,[ArchivedDate]
221+
,[ArchivedByAdminID]
222+
,[IncludeDevelopment]
223+
,[ParentSelfAssessmentID]
224+
,[NRPProfessionalGroupID]
225+
,[NRPSubGroupID]
226+
,[NRPRoleID]
227+
,[PublishStatusID]
228+
,[UpdatedByAdminID]
229+
,[National]
230+
,[Public]
231+
,[Archived]
232+
,[LastEdit]
233+
,[SupervisorSelfAssessmentReview]
234+
,[SupervisorResultsReview]
235+
,[RAGResults]
236+
,[LinearNavigation]
237+
,[CategoryID]
238+
,[UseDescriptionExpanders]
239+
,[ManageOptionalCompetenciesPrompt]
240+
,[Vocabulary]
241+
,[SignOffRequestorStatement]
242+
,[SignOffSupervisorStatement]
243+
,[QuestionLabel]
244+
,[DescriptionLabel]
245+
,[EnforceRoleRequirementsForSignOff]
246+
,[ReviewerCommentsLabel]
247+
,[ManageSupervisorsDescription]
248+
,[IncludeRequirementsFilters]
249+
,[MinimumOptionalCompetencies]
250+
,[RetirementDate]
251+
,[EnrolmentCutoffDate]
252+
,[RetirementReason]
253+
FROM SelfAssessments
254+
WHERE ID = @selfAssessmentId",
255+
new { selfAssessmentId }
256+
).SingleOrDefault();
257+
}
258+
public SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId)
259+
{
260+
var date = connection.QueryFirstOrDefault<SelfAssessment>(
261+
@"SELECT Id,Name,[RetirementDate]
262+
FROM SelfAssessments
263+
WHERE ID = @selfAssessmentId"
264+
,
265+
new { selfAssessmentId }
266+
);
267+
return date;
268+
}
269+
207270
public (IEnumerable<SelfAssessmentDelegate>, int) GetSelfAssessmentDelegates(string searchString, int offSet, int itemsPerPage, string sortBy, string sortDirection,
208271
int? selfAssessmentId, int centreId, bool? isDelegateActive, bool? removed, bool? submitted, bool? signedOff)
209272
{

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/Controllers/LearningPortalController/SelfAssessment.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,22 +1532,6 @@ ManageOptionalCompetenciesViewModel model
15321532
);
15331533
}
15341534
}
1535-
var optionalCompetency =
1536-
(selfAssessmentService.GetCandidateAssessmentOptionalCompetencies(selfAssessmentId, delegateUserId)).Where(x => !x.IncludedInSelfAssessment);
1537-
if (optionalCompetency.Any())
1538-
{
1539-
foreach (var optinal in optionalCompetency)
1540-
{
1541-
var selfAssessmentResults = selfAssessmentService.GetSelfAssessmentResultswithSupervisorVerificationsForDelegateSelfAssessmentCompetency(delegateUserId, selfAssessmentId, optinal.Id);
1542-
if (selfAssessmentResults.Any())
1543-
{
1544-
foreach (var item in selfAssessmentResults)
1545-
{
1546-
selfAssessmentService.RemoveReviewCandidateAssessmentOptionalCompetencies(item.Id);
1547-
}
1548-
}
1549-
}
1550-
}
15511535
if (model.GroupOptionalCompetenciesChecked != null)
15521536
{
15531537
var optionalCompetencies =
@@ -1566,6 +1550,23 @@ ManageOptionalCompetenciesViewModel model
15661550

15671551
}
15681552

1553+
var optionalCompetency =
1554+
(selfAssessmentService.GetCandidateAssessmentOptionalCompetencies(selfAssessmentId, delegateUserId)).Where(x => !x.IncludedInSelfAssessment);
1555+
if (optionalCompetency.Any())
1556+
{
1557+
foreach (var optinal in optionalCompetency)
1558+
{
1559+
var selfAssessmentResults = selfAssessmentService.GetSelfAssessmentResultswithSupervisorVerificationsForDelegateSelfAssessmentCompetency(delegateUserId, selfAssessmentId, optinal.Id);
1560+
if (selfAssessmentResults.Any())
1561+
{
1562+
foreach (var item in selfAssessmentResults)
1563+
{
1564+
selfAssessmentService.RemoveReviewCandidateAssessmentOptionalCompetencies(item.Id);
1565+
}
1566+
}
1567+
}
1568+
}
1569+
15691570
var recentResults = selfAssessmentService.GetMostRecentResults(selfAssessmentId, User.GetCandidateIdKnownNotNull()).ToList();
15701571

15711572
bool isVerificationPending = recentResults?.SelectMany(comp => comp.AssessmentQuestions).Where(quest => quest.Required)

DigitalLearningSolutions.Web/Controllers/SuperAdmin/Centres/CentresController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System;
2222
using System.Collections.Generic;
2323
using System.Linq;
24+
using System.Text.RegularExpressions;
2425

2526
namespace DigitalLearningSolutions.Web.Controllers.SuperAdmin.Centres
2627
{
@@ -330,7 +331,8 @@ public IActionResult ManageCentreManager(EditCentreManagerDetailsViewModel editC
330331
{
331332
editCentreManagerDetailsViewModel.FirstName = editCentreManagerDetailsViewModel.FirstName == null ? string.Empty : editCentreManagerDetailsViewModel.FirstName.Trim();
332333
editCentreManagerDetailsViewModel.LastName = editCentreManagerDetailsViewModel.LastName == null ? string.Empty : editCentreManagerDetailsViewModel.LastName.Trim();
333-
editCentreManagerDetailsViewModel.Telephone = editCentreManagerDetailsViewModel.Telephone?.Trim() ?? string.Empty;
334+
editCentreManagerDetailsViewModel.Telephone = editCentreManagerDetailsViewModel.Telephone != null ? Regex.Replace(editCentreManagerDetailsViewModel.Telephone, @"\s+", "")
335+
: string.Empty; ;
334336
if (!ModelState.IsValid)
335337
{
336338
return View(editCentreManagerDetailsViewModel);

DigitalLearningSolutions.Web/Controllers/SupervisorController/Supervisor.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,18 @@ public IActionResult EnrolSetCompetencyAssessment(int supervisorDelegateId, int
784784
};
785785
return View("EnrolDelegateOnProfileAssessment", model);
786786
}
787+
var retirementDate = selfAssessmentService.GetSelfAssessmentById(selfAssessmentID).RetirementDate;
788+
if (retirementDate?.Date is DateTime date && date >= DateTime.Today &&
789+
date <= DateTime.Today.AddDays(14))
790+
{
791+
var model = new RetiringSelfAssessmentViewModel()
792+
{
793+
SelfAssessmentID = selfAssessmentID,
794+
SupervisorDelegateID = supervisorDelegateId,
795+
RetirementDate = retirementDate
796+
};
797+
return View("ConfirmRetiringSelfAssessment", model);
798+
}
787799

788800
sessionEnrolOnCompetencyAssessment.SelfAssessmentID = selfAssessmentID;
789801
multiPageFormService.SetMultiPageFormData(
@@ -798,6 +810,34 @@ public IActionResult EnrolSetCompetencyAssessment(int supervisorDelegateId, int
798810
);
799811
}
800812

813+
[HttpPost]
814+
public IActionResult RetiringSelfAssessmentConfirmed(RetiringSelfAssessmentViewModel retiringSelfAssessment)
815+
{
816+
if (ModelState.IsValid && retiringSelfAssessment.ActionConfirmed)
817+
{
818+
var sessionEnrolOnRoleProfile = multiPageFormService.GetMultiPageFormData<SessionEnrolOnRoleProfile>(
819+
MultiPageFormDataFeature.EnrolDelegateOnProfileAssessment,
820+
TempData
821+
).GetAwaiter().GetResult();
822+
823+
sessionEnrolOnRoleProfile.SelfAssessmentID = retiringSelfAssessment.SelfAssessmentID;
824+
multiPageFormService.SetMultiPageFormData(
825+
sessionEnrolOnRoleProfile,
826+
MultiPageFormDataFeature.EnrolDelegateOnProfileAssessment,
827+
TempData
828+
);
829+
return RedirectToAction(
830+
"EnrolDelegateCompleteBy",
831+
"Supervisor",
832+
new { supervisorDelegateId = retiringSelfAssessment.SupervisorDelegateID }
833+
);
834+
}
835+
else
836+
{
837+
return View("ConfirmRetiringSelfAssessment", retiringSelfAssessment);
838+
}
839+
}
840+
801841
[Route("/Supervisor/Staff/{supervisorDelegateId}/ProfileAssessment/Enrol/CompleteBy")]
802842
[ResponseCache(CacheProfileName = "Never")]
803843
[TypeFilter(

DigitalLearningSolutions.Web/Services/SelfAssessmentService.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public interface ISelfAssessmentService
1414
{
1515
//Self Assessments
1616
string? GetSelfAssessmentNameById(int selfAssessmentId);
17+
SelfAssessment? GetSelfAssessmentById(int selfAssessmentId);
1718
// Candidate Assessments
1819
IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId, int? adminIdCategoryID);
1920
IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId);
@@ -162,6 +163,7 @@ public IEnumerable<SelfAssessmentResult> GetSelfAssessmentResultswithSupervisorV
162163
int competencyId
163164
);
164165
void RemoveReviewCandidateAssessmentOptionalCompetencies(int id);
166+
SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId);
165167
}
166168

167169
public class SelfAssessmentService : ISelfAssessmentService
@@ -466,6 +468,11 @@ public void RemoveEnrolment(int selfAssessmentId, int delegateUserId)
466468
return selfAssessmentDataService.GetSelfAssessmentNameById(selfAssessmentId);
467469
}
468470

471+
public SelfAssessment? GetSelfAssessmentById(int selfAssessmentId)
472+
{
473+
return selfAssessmentDataService.GetSelfAssessmentById(selfAssessmentId);
474+
}
475+
469476
public (SelfAssessmentDelegatesData, int?) GetSelfAssessmentDelegatesPerPage(string searchString, int offSet, int itemsPerPage, string sortBy, string sortDirection,
470477
int? selfAssessmentId, int centreId, bool? isDelegateActive, bool? removed, bool? submitted, bool? signedOff, int? adminCategoryId)
471478
{
@@ -610,5 +617,9 @@ public void RemoveReviewCandidateAssessmentOptionalCompetencies(int id)
610617
{
611618
selfAssessmentDataService.RemoveReviewCandidateAssessmentOptionalCompetencies(id);
612619
}
620+
public SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId)
621+
{
622+
return selfAssessmentDataService.GetSelfAssessmentRetirementDateById(selfAssessmentId);
623+
}
613624
}
614625
}
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace DigitalLearningSolutions.Web.ViewModels.Supervisor
2+
{
3+
using DigitalLearningSolutions.Web.Attributes;
4+
using System;
5+
6+
public class RetiringSelfAssessmentViewModel
7+
{
8+
public int SelfAssessmentID { get; set; }
9+
public int SupervisorDelegateID { get; set; }
10+
public DateTime? RetirementDate { get; set; }
11+
[BooleanMustBeTrue(ErrorMessage = "Please tick the checkbox to confirm you wish to perform this action")]
12+
public bool ActionConfirmed { get; set; }
13+
}
14+
}
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)