Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface ISelfAssessmentDataService
{
//Self Assessments
string? GetSelfAssessmentNameById(int selfAssessmentId);
SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId);

// CompetencyDataService
IEnumerable<int> GetCompetencyIdsForSelfAssessment(int selfAssessmentId);
Expand Down Expand Up @@ -204,6 +205,18 @@ FROM SelfAssessments
return name;
}

public SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId)
{
var date = connection.QueryFirstOrDefault<SelfAssessment>(
@"SELECT Id,Name,[RetirementDate]
FROM SelfAssessments
WHERE ID = @selfAssessmentId"
,
new { selfAssessmentId }
);
return date;
}

public (IEnumerable<SelfAssessmentDelegate>, int) GetSelfAssessmentDelegates(string searchString, int offSet, int itemsPerPage, string sortBy, string sortDirection,
int? selfAssessmentId, int centreId, bool? isDelegateActive, bool? removed, bool? submitted, bool? signedOff)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class SelfAssessment : CurrentLearningItem
public string? QuestionLabel { get; set; }
public string? DescriptionLabel { get; set; }
public DateTime? RetirementDate { get; set; }

public DateTime? EnrolmentCutoffDate { get; set; }
public string? RetirementReason { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public IEnumerable<SelfAssessmentResult> GetSelfAssessmentResultswithSupervisorV
int competencyId
);
void RemoveReviewCandidateAssessmentOptionalCompetencies(int id);
SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId);
}

public class SelfAssessmentService : ISelfAssessmentService
Expand Down Expand Up @@ -610,5 +611,9 @@ public void RemoveReviewCandidateAssessmentOptionalCompetencies(int id)
{
selfAssessmentDataService.RemoveReviewCandidateAssessmentOptionalCompetencies(id);
}
public SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId)
{
return selfAssessmentDataService.GetSelfAssessmentRetirementDateById(selfAssessmentId);
}
}
}
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -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 {
<partial name="Shared/_NavMenuItems" />
}
<form asp-controller="LearningPortal" asp-action="ConfirmRetirement" method="post">
<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-full word-break">
@if (errorHasOccurred)
{
<vc:error-summary order-of-property-names="@(new[] { nameof(Model.ActionConfirmed) })" />
}
<h1 id="page-heading">Confirm Retirement</h1>
<p class="nhsuk-body-m">You are about to enrol on a retiring <strong>@Model.Name</strong> self-assessment.</p>
<p class="nhsuk-body-m"> Retirement date: <strong>@Model.RetirementDate?.ToString("dd MMMM yyyy")</strong> </p>
<p class="nhsuk-body-m">After this date, the <strong>@Model.Name</strong> self-assessment will no longer be accessible.</p>

<p class="nhsuk-body-m">Please consider:</p>
<ul class="nhsuk-list nhsuk-list--bullet">
<li> you may have limited time to complete the self-assessment</li>


<li> if you do not complete it before the retirement date, your progress may not be saved</li>
</ul>
<p class="nhsuk-body-m">To continue, you must acknowledge that you understand the self-assessment is retiring and still wish to enrol.</p>


<p class="nhsuk-body-m">
<vc:single-checkbox asp-for="@nameof(Model.ActionConfirmed)"
label="I understand this self-assessment is retiring and still want to enrol."
hint-text="" />
</p>
<button type="submit" class="nhsuk-button">Enrol now</button>
<a class="nhsuk-button nhsuk-button--secondary"
role="button"
asp-controller="LearningPortal" asp-action="Available">
Cancel
</a>
@Html.HiddenFor(m => m.SelfAssessmentId)
@Html.HiddenFor(m => m.RetirementDate)
</div>
</div>
</form>

Loading