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 @@ -17,5 +17,6 @@ public class SessionEnrolDelegate
public bool IsSelfAssessment { get; set; }
public int AssessmentVersion { get; set; }
public int? AssessmentCategoryID { get; set; }
public bool ActionConfirmed { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class EnrolControllerTests
private ISupervisorService supervisorService = null!;
private ICourseService courseService = null!;
private IEnrolService enrolService = null!;
private ISelfAssessmentService selfAssessmentService = null!;
private HttpRequest httpRequest = null!;
private HttpResponse httpResponse = null!;
private HttpContext httpContext = null!;
Expand All @@ -35,6 +36,7 @@ public void Setup()
supervisorService = A.Fake<ISupervisorService>();
enrolService = A.Fake<IEnrolService>();
courseService = A.Fake<ICourseService>();
selfAssessmentService = A.Fake<ISelfAssessmentService>();
sessionEnrolDelegate = A.Fake<SessionEnrolDelegate>();

httpRequest = A.Fake<HttpRequest>();
Expand All @@ -46,7 +48,8 @@ public void Setup()
multiPageFormService,
supervisorService,
enrolService,
courseService)
courseService,
selfAssessmentService)
.WithMockHttpContext(httpRequest, null, null, httpResponse)
.WithMockTempData()
.WithDefaultContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using DigitalLearningSolutions.Web.Extensions;
using DigitalLearningSolutions.Web.Helpers;
using DigitalLearningSolutions.Web.ServiceFilter;
using DigitalLearningSolutions.Web.ViewModels.Common;
using DigitalLearningSolutions.Web.ViewModels.Common.SearchablePage;
using DigitalLearningSolutions.Web.ViewModels.Supervisor;
using GDS.MultiPageFormData.Enums;
Expand Down Expand Up @@ -796,7 +797,7 @@ public IActionResult EnrolSetRoleProfile(int supervisorDelegateId, int selfAsses
);

var retirementDate = selfAssessmentService.GetSelfAssessmentById(selfAssessmentID).RetirementDate;
if (CheckRetirementDate(retirementDate))
if (SelfAssessmentHelper.CheckRetirementDate(retirementDate))
{
return RedirectToAction("ConfirmRetiringSelfAssessment", "Supervisor", new { supervisorDelegateId });
}
Expand All @@ -817,14 +818,14 @@ public IActionResult ConfirmRetiringSelfAssessment(int supervisorDelegateId)
).GetAwaiter().GetResult();

var retirementDate = selfAssessmentService.GetSelfAssessmentById((int)sessionEnrolOnRoleProfile.SelfAssessmentID).RetirementDate;
if (!CheckRetirementDate((retirementDate)))
if (!SelfAssessmentHelper.CheckRetirementDate((retirementDate)))
{
return RedirectToAction("StatusCode", "LearningSolutions", new { code = 410 });
}
var model = new RetiringSelfAssessmentViewModel()
{
SelfAssessmentID = (int)sessionEnrolOnRoleProfile.SelfAssessmentID,
SupervisorDelegateID = supervisorDelegateId,
RouteID = supervisorDelegateId,
RetirementDate = retirementDate,
ActionConfirmed = sessionEnrolOnRoleProfile.ActionConfirmed
};
Expand Down Expand Up @@ -853,7 +854,7 @@ public IActionResult ConfirmRetiringSelfAssessment(RetiringSelfAssessmentViewMod
return RedirectToAction(
"EnrolDelegateCompleteBy",
"Supervisor",
new { supervisorDelegateId = retiringSelfAssessment.SupervisorDelegateID }
new { supervisorDelegateId = retiringSelfAssessment.RouteID }
);
}
else
Expand All @@ -876,7 +877,7 @@ public IActionResult EnrolDelegateCompleteBy(int supervisorDelegateId, int? day,
).GetAwaiter().GetResult();

var retirementDate = selfAssessmentService.GetSelfAssessmentById((int)sessionEnrolOnRoleProfile.SelfAssessmentID).RetirementDate;
if (CheckRetirementDate(retirementDate) && !sessionEnrolOnRoleProfile.ActionConfirmed)
if (SelfAssessmentHelper.CheckRetirementDate(retirementDate) && !sessionEnrolOnRoleProfile.ActionConfirmed)
{
return RedirectToAction("ConfirmRetiringSelfAssessment", "Supervisor", new { supervisorDelegateId });
}
Expand Down Expand Up @@ -1030,7 +1031,7 @@ public IActionResult EnrolDelegateSummary(int supervisorDelegateId)
);

var retirementDate = selfAssessmentService.GetSelfAssessmentById((int)sessionEnrolOnRoleProfile.SelfAssessmentID).RetirementDate;
if (CheckRetirementDate(retirementDate) && !sessionEnrolOnRoleProfile.ActionConfirmed)
if (SelfAssessmentHelper.CheckRetirementDate(retirementDate) && !sessionEnrolOnRoleProfile.ActionConfirmed)
{
return RedirectToAction("ConfirmRetiringSelfAssessment", "Supervisor", new { supervisorDelegateId });
}
Expand Down Expand Up @@ -1586,15 +1587,5 @@ private static string RenderRazorViewToString(Controller controller, string view
return sw.GetStringBuilder().ToString();
}
}

private bool CheckRetirementDate(DateTime? date)
{
if (date == null)
return false;

DateTime retirementOffsetDate = DateTime.Today.AddDays(14);
DateTime today = DateTime.Today;
return (date >= today && date <= retirementOffsetDate);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

namespace DigitalLearningSolutions.Web.Controllers.TrackingSystem.Delegates
{
using DigitalLearningSolutions.Data.Models.SessionData.Supervisor;
using DigitalLearningSolutions.Data.Models.Supervisor;
using DigitalLearningSolutions.Data.Utilities;
using DigitalLearningSolutions.Web.ServiceFilter;
using DigitalLearningSolutions.Web.ViewModels.Common;
using Pipelines.Sockets.Unofficial;

[FeatureGate(FeatureFlags.RefactoredTrackingSystem)]
[Authorize(Policy = CustomPolicies.UserCentreAdmin)]
Expand All @@ -29,18 +33,21 @@ public partial class EnrolController : Controller
private readonly ISupervisorService supervisorService;
private readonly IEnrolService enrolService;
private readonly ICourseService courseService;
private readonly ISelfAssessmentService selfAssessmentService;

public EnrolController(
IMultiPageFormService multiPageFormService,
ISupervisorService supervisorService,
IEnrolService enrolService,
ICourseService courseService
ICourseService courseService,
ISelfAssessmentService selfAssessmentService
)
{
this.multiPageFormService = multiPageFormService;
this.supervisorService = supervisorService;
this.enrolService = enrolService;
this.courseService = courseService;
this.selfAssessmentService = selfAssessmentService;
}

public IActionResult StartEnrolProcess(int delegateId, int delegateUserId, string delegateName)
Expand Down Expand Up @@ -116,6 +123,15 @@ public IActionResult Index(int delegateId, EnrolCurrentLearningViewModel enrolCu
return View(model);
}

if (sessionEnrol.AssessmentID.HasValue && sessionEnrol.AssessmentID != enrolCurrentLearningViewModel.SelectedActivity)
{
var delegateUserID = sessionEnrol.DelegateUserID;
var userName = sessionEnrol.DelegateName;
sessionEnrol = new SessionEnrolDelegate();
sessionEnrol.DelegateID = delegateId;
sessionEnrol.DelegateName = userName;
sessionEnrol.DelegateUserID = delegateUserID;
}
sessionEnrol.AssessmentID = enrolCurrentLearningViewModel.SelectedActivity;
var availableCourse = selfAssessments as List<AvailableCourse>;
var selectedCourse = availableCourse.Find(x => x.Id == enrolCurrentLearningViewModel.SelectedActivity);
Expand All @@ -126,17 +142,74 @@ public IActionResult Index(int delegateId, EnrolCurrentLearningViewModel enrolCu

multiPageFormService.SetMultiPageFormData(
sessionEnrol,
MultiPageFormDataFeature.EnrolDelegateInActivity,
MultiPageFormDataFeature.EnrolDelegateInActivity,
TempData
);

if (HasNotConfirmedRetiring(sessionEnrol.IsSelfAssessment, (int)sessionEnrol.AssessmentID, delegateId, sessionEnrol.ActionConfirmed))
{
return RedirectToAction("ConfirmRetiring", "Enrol", new { delegateId });
}

return RedirectToAction(
"EnrolCompleteBy",
"Enrol",
new { delegateId }
);
}

public IActionResult ConfirmRetiring(int delegateId)
{
var sessionEnrol = multiPageFormService.GetMultiPageFormData<SessionEnrolDelegate>(
MultiPageFormDataFeature.EnrolDelegateInActivity,
TempData
).GetAwaiter().GetResult();

var retirementDate = selfAssessmentService.GetSelfAssessmentById((int)sessionEnrol.AssessmentID).RetirementDate;
if (!SelfAssessmentHelper.CheckRetirementDate((retirementDate)))
{
return RedirectToAction("StatusCode", "LearningSolutions", new { code = 410 });
}
var model = new RetiringSelfAssessmentViewModel()
{
SelfAssessmentID = (int)sessionEnrol.AssessmentID,
RouteID = (int)sessionEnrol.DelegateID,
RetirementDate = retirementDate,
ActionConfirmed = sessionEnrol.ActionConfirmed
};
return View("ConfirmRetiring", model);
}

[HttpPost]
public IActionResult ConfirmRetiring(RetiringSelfAssessmentViewModel retiringSelfAssessment)
{
var sessionEnrol = multiPageFormService.GetMultiPageFormData<SessionEnrolDelegate>(
MultiPageFormDataFeature.EnrolDelegateInActivity,
TempData
).GetAwaiter().GetResult();

sessionEnrol.AssessmentID = retiringSelfAssessment.SelfAssessmentID;
sessionEnrol.ActionConfirmed = retiringSelfAssessment.ActionConfirmed;
multiPageFormService.SetMultiPageFormData(
sessionEnrol,
MultiPageFormDataFeature.EnrolDelegateInActivity,
TempData
);

if (ModelState.IsValid && retiringSelfAssessment.ActionConfirmed)
{
return RedirectToAction(
"EnrolCompleteBy",
"Enrol",
new { delegateId = retiringSelfAssessment.RouteID }
);
}
else
{
return View("ConfirmRetiring", retiringSelfAssessment);
}
}

[HttpGet]
[TypeFilter(
typeof(RedirectToErrorEmptySessionData),
Expand All @@ -145,9 +218,15 @@ public IActionResult Index(int delegateId, EnrolCurrentLearningViewModel enrolCu
public IActionResult EnrolCompleteBy(int delegateId)
{
var sessionEnrol = multiPageFormService.GetMultiPageFormData<SessionEnrolDelegate>(
MultiPageFormDataFeature.EnrolDelegateInActivity,
TempData
).GetAwaiter().GetResult();
MultiPageFormDataFeature.EnrolDelegateInActivity,
TempData
).GetAwaiter().GetResult();

if (HasNotConfirmedRetiring(sessionEnrol.IsSelfAssessment, (int)sessionEnrol.AssessmentID, delegateId, sessionEnrol.ActionConfirmed))
{
return RedirectToAction("ConfirmRetiring", "Enrol", new { delegateId });
}

multiPageFormService.SetMultiPageFormData(
sessionEnrol,
MultiPageFormDataFeature.EnrolDelegateInActivity,
Expand Down Expand Up @@ -202,6 +281,12 @@ public IActionResult EnrolDelegateSupervisor(int delegateId)
var sessionEnrol = multiPageFormService.GetMultiPageFormData<SessionEnrolDelegate>(
MultiPageFormDataFeature.EnrolDelegateInActivity,
TempData).GetAwaiter().GetResult();

if (HasNotConfirmedRetiring(sessionEnrol.IsSelfAssessment, (int)sessionEnrol.AssessmentID, delegateId, sessionEnrol.ActionConfirmed))
{
return RedirectToAction("ConfirmRetiring", "Enrol", new { delegateId });
}

var supervisorList = supervisorService.GetSupervisorForEnrolDelegate(centreId.Value, sessionEnrol.AssessmentCategoryID.Value);
if (!sessionEnrol.IsSelfAssessment)
{
Expand Down Expand Up @@ -283,6 +368,12 @@ public IActionResult EnrolDelegateSupervisor(int delegateId, EnrolSupervisorView
public IActionResult EnrolDelegateSummary(int delegateId)
{
var sessionEnrol = multiPageFormService.GetMultiPageFormData<SessionEnrolDelegate>(MultiPageFormDataFeature.EnrolDelegateInActivity, TempData).GetAwaiter().GetResult();

if (HasNotConfirmedRetiring(sessionEnrol.IsSelfAssessment, (int)sessionEnrol.AssessmentID, delegateId, sessionEnrol.ActionConfirmed))
{
return RedirectToAction("ConfirmRetiring", "Enrol", new { delegateId });
}

var roles = supervisorService.GetSupervisorRolesBySelfAssessmentIdForSupervisor(sessionEnrol.AssessmentID.GetValueOrDefault()).ToArray();
var clockUtility = new ClockUtility();
var monthDiffrence = "";
Expand All @@ -303,6 +394,7 @@ public IActionResult EnrolDelegateSummary(int delegateId)
model.IsSelfAssessment = sessionEnrol.IsSelfAssessment;
model.SupervisorRoleName = sessionEnrol.SelfAssessmentSupervisorRoleName;
model.RoleCount = roles.Count();
ViewBag.actionConfirmed = sessionEnrol.ActionConfirmed;
return View(model);
}

Expand Down Expand Up @@ -345,5 +437,15 @@ private int GetAdminID()
{
return User.GetCustomClaimAsRequiredInt(CustomClaimTypes.UserAdminId);
}

private bool HasNotConfirmedRetiring(bool IsSelfAssessment, int selfAssessmentId, int delegateId, bool actionConfirmed)
{
if (IsSelfAssessment)
{
var retirementDate = selfAssessmentService.GetSelfAssessmentById(selfAssessmentId).RetirementDate;
return SelfAssessmentHelper.CheckRetirementDate(retirementDate) && !actionConfirmed;
}
return false;
}
}
}
17 changes: 17 additions & 0 deletions DigitalLearningSolutions.Web/Helpers/SelfAssessmentHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace DigitalLearningSolutions.Web.Helpers
{
using System;

public static class SelfAssessmentHelper
{
public static bool CheckRetirementDate(DateTime? date)
{
if (date == null)
return false;

DateTime retirementOffsetDate = DateTime.Today.AddDays(14);
DateTime today = DateTime.Today;
return (date >= today && date <= retirementOffsetDate);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace DigitalLearningSolutions.Web.ViewModels.Supervisor
namespace DigitalLearningSolutions.Web.ViewModels.Common
{
using DigitalLearningSolutions.Web.Attributes;
using System;

public class RetiringSelfAssessmentViewModel
{
public int SelfAssessmentID { get; set; }
public int SupervisorDelegateID { get; set; }
public int RouteID { 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; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@using DigitalLearningSolutions.Web.Extensions
@using DigitalLearningSolutions.Web.ViewModels.Supervisor
@using DigitalLearningSolutions.Web.ViewModels.Common
@using Microsoft.Extensions.Configuration
@model RetiringSelfAssessmentViewModel;
@inject IConfiguration Configuration;
Expand Down Expand Up @@ -40,12 +40,12 @@
Continue
</button>
@Html.HiddenFor(m => m.SelfAssessmentID)
@Html.HiddenFor(m => m.SupervisorDelegateID)
@Html.HiddenFor(m => m.RouteID)
@Html.HiddenFor(m => m.RetirementDate)
</form>
<div class="nhsuk-back-link">
<a class="nhsuk-back-link__link" asp-controller="Supervisor"
asp-action="DelegateProfileAssessments" asp-route-supervisorDelegateId="@Model.SupervisorDelegateID">
asp-action="DelegateProfileAssessments" asp-route-supervisorDelegateId="@Model.RouteID">
<svg class="nhsuk-icon nhsuk-icon__chevron-left" focusable='false' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<path d="M13.41 12l5.3-5.29a1 1 0 1 0-1.42-1.42L12 10.59l-5.29-5.3a1 1 0 0 0-1.42 1.42l5.3 5.29-5.3 5.29a1 1 0 0 0 0 1.42 1 1 0 0 0 1.42 0l5.29-5.3 5.29 5.3a1 1 0 0 0 1.42 0 1 1 0 0 0 0-1.42z"></path>
</svg>
Expand Down
Loading
Loading