Skip to content

Commit d2f4751

Browse files
committed
TD-5307 Implements remove source framework logic and confirm page
1 parent 7c72c5e commit d2f4751

File tree

6 files changed

+172
-27
lines changed

6 files changed

+172
-27
lines changed

DigitalLearningSolutions.Data/DataServices/CompetencyAssessmentDataService.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,17 @@ int categoryId
5252
bool UpdateRoleProfileLinksTaskStatus(int assessmentId, bool taskStatus);
5353
bool UpdateFrameworkLinksTaskStatus(int assessmentId, bool taskStatus);
5454
bool RemoveSelfAssessmentFramework(int assessmentId, int frameworkId, int adminId);
55+
bool UpdateSelectCompetenciesTaskStatus(int assessmentId, bool taskStatus, bool? previousStatus);
56+
bool UpdateOptionalCompetenciesTaskStatus(int assessmentId, bool taskStatus, bool? previousStatus);
57+
bool UpdateRoleRequirementsTaskStatus(int assessmentId, bool taskStatus, bool? previousStatus);
5558

5659
//INSERT DATA
5760
int InsertCompetencyAssessment(int adminId, int centreId, string competencyAssessmentName);
5861
bool InsertSelfAssessmentFramework(int adminId, int selfAssessmentId, int frameworkId);
62+
5963
//DELETE DATA
64+
bool RemoveFrameworkCompetenciesFromAssessment(int competencyAssessmentId, int frameworkId);
65+
6066
}
6167

6268
public class CompetencyAssessmentDataService : ICompetencyAssessmentDataService
@@ -552,5 +558,78 @@ FROM SelfAssessmentStructure AS sas INNER JOIN
552558
new { assessmentId, frameworkId }
553559
);
554560
}
561+
562+
public bool RemoveFrameworkCompetenciesFromAssessment(int competencyAssessmentId, int frameworkId)
563+
{
564+
var numberOfAffectedRows = connection.Execute(
565+
@"DELETE FROM SelfAssessmentStructure
566+
FROM SelfAssessmentStructure INNER JOIN
567+
FrameworkCompetencies AS fc ON SelfAssessmentStructure.CompetencyID = fc.CompetencyID INNER JOIN
568+
SelfAssessmentFrameworks AS saf ON fc.FrameworkID = saf.FrameworkId AND SelfAssessmentStructure.SelfAssessmentID = saf.SelfAssessmentId
569+
WHERE (saf.SelfAssessmentId = @competencyAssessmentId) AND (saf.FrameworkId = @frameworkId)",
570+
new { competencyAssessmentId, frameworkId }
571+
);
572+
if (numberOfAffectedRows < 1)
573+
{
574+
logger.LogWarning(
575+
"Not removing competencies linked to source framework as db update failed. " +
576+
$"assessmentId: {competencyAssessmentId}, taskStatus: {frameworkId}"
577+
);
578+
return false;
579+
}
580+
return true;
581+
}
582+
583+
public bool UpdateSelectCompetenciesTaskStatus(int assessmentId, bool taskStatus, bool? previousStatus)
584+
{
585+
var numberOfAffectedRows = connection.Execute(
586+
@"UPDATE SelfAssessmentTaskStatus SET SelectCompetenciesTaskStatus = @taskStatus
587+
WHERE SelfAssessmentId = @assessmentId AND (@previousStatus IS NULL OR SelectCompetenciesTaskStatus = @previousStatus)",
588+
new { assessmentId, taskStatus, previousStatus }
589+
);
590+
if (numberOfAffectedRows < 1)
591+
{
592+
logger.LogWarning(
593+
"Not updating SelectCompetenciesTaskStatus as db update failed. " +
594+
$"assessmentId: {assessmentId}, taskStatus: {taskStatus}"
595+
);
596+
return false;
597+
}
598+
return true;
599+
}
600+
public bool UpdateOptionalCompetenciesTaskStatus(int assessmentId, bool taskStatus, bool? previousStatus)
601+
{
602+
var numberOfAffectedRows = connection.Execute(
603+
@"UPDATE SelfAssessmentTaskStatus SET OptionalCompetenciesTaskStatus = @taskStatus
604+
WHERE SelfAssessmentId = @assessmentId AND (@previousStatus IS NULL OR OptionalCompetenciesTaskStatus = @previousStatus)",
605+
new { assessmentId, taskStatus, previousStatus }
606+
);
607+
if (numberOfAffectedRows < 1)
608+
{
609+
logger.LogWarning(
610+
"Not updating OptionalCompetenciesTaskStatus as db update failed. " +
611+
$"assessmentId: {assessmentId}, taskStatus: {taskStatus}"
612+
);
613+
return false;
614+
}
615+
return true;
616+
}
617+
public bool UpdateRoleRequirementsTaskStatus(int assessmentId, bool taskStatus, bool? previousStatus)
618+
{
619+
var numberOfAffectedRows = connection.Execute(
620+
@"UPDATE SelfAssessmentTaskStatus SET RoleRequirementsTaskStatus = @taskStatus
621+
WHERE SelfAssessmentId = @assessmentId AND (@previousStatus IS NULL OR RoleRequirementsTaskStatus = @previousStatus)",
622+
new { assessmentId, taskStatus, previousStatus }
623+
);
624+
if (numberOfAffectedRows < 1)
625+
{
626+
logger.LogWarning(
627+
"Not updating RoleRequirementsTaskStatus as db update failed. " +
628+
$"assessmentId: {assessmentId}, taskStatus: {taskStatus}"
629+
);
630+
return false;
631+
}
632+
return true;
633+
}
555634
}
556635
}

DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
using DigitalLearningSolutions.Data.Models.Centres;
1616
using DigitalLearningSolutions.Data.Models.Frameworks;
1717
using Microsoft.CodeAnalysis.CSharp.Syntax;
18+
using DigitalLearningSolutions.Data.Models.Courses;
19+
using DigitalLearningSolutions.Web.Services;
20+
using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.Delegates.GroupCourses;
1821

1922
public partial class CompetencyAssessmentsController
2023
{
@@ -465,5 +468,18 @@ public IActionResult RemoveFramework(int frameworkId, int competencyAssessmentId
465468
}
466469
return RedirectToAction("SelectFrameworkSources", new { competencyAssessmentId, actionName = "Summary" });
467470
}
471+
[HttpPost]
472+
[Route("/CompetencyAssessments/{competencyAssessmentId}/Frameworks/{frameworkId}/Remove")]
473+
public IActionResult RemoveFramework(ConfirmRemoveFrameworkSourceViewModel model)
474+
{
475+
if (!ModelState.IsValid)
476+
{
477+
return View("ConfirmRemoveFrameworkSource", model);
478+
}
479+
var adminId = GetAdminID();
480+
competencyAssessmentService.RemoveFrameworkCompetenciesFromAssessment(model.CompetencyAssessmentId, model.FrameworkId);
481+
competencyAssessmentService.RemoveSelfAssessmentFramework(model.CompetencyAssessmentId, model.FrameworkId, adminId);
482+
return RedirectToAction("SelectFrameworkSources", new { model.CompetencyAssessmentId, actionName = "Summary" });
483+
}
468484
}
469485
}

DigitalLearningSolutions.Web/Helpers/DisplayStringHelper.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ public static string GetPluralitySuffix(int number)
7171
{
7272
return number == 1 ? string.Empty : "s";
7373
}
74+
public static string PluraliseStringIfRequired(string input, int number)
75+
{
76+
if (number == 1)
77+
{
78+
return input;
79+
}
80+
else if (input.EndsWith("y"))
81+
{
82+
return input.Substring(0, input.Length - 1) + "ies";
83+
}
84+
else
85+
{
86+
return input + "s";
87+
}
88+
}
7489

7590
public static string? ReplaceNonAlphaNumericSpaceChars(string? input, string replacement)
7691
{

DigitalLearningSolutions.Web/Services/CompetencyAssessmentService.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using DigitalLearningSolutions.Data.DataServices;
22
using DigitalLearningSolutions.Data.Models.Common;
33
using DigitalLearningSolutions.Data.Models.CompetencyAssessments;
4+
using DocumentFormat.OpenXml.EMMA;
45
using System.Collections.Generic;
56
using System.Threading.Tasks;
67

@@ -39,11 +40,18 @@ public interface ICompetencyAssessmentService
3940
bool UpdateVocabularyTaskStatus(int assessmentId, bool taskStatus);
4041
bool UpdateRoleProfileLinksTaskStatus(int assessmentId, bool taskStatus);
4142
bool UpdateFrameworkLinksTaskStatus(int assessmentId, bool taskStatus);
43+
bool UpdateSelectCompetenciesTaskStatus(int competencyAssessmentId, bool taskStatus, bool? previousStatus);
44+
bool UpdateOptionalCompetenciesTaskStatus(int assessmentId, bool taskStatus, bool? previousStatus);
45+
bool UpdateRoleRequirementsTaskStatus(int assessmentId, bool taskStatus, bool? previousStatus);
4246

4347
//INSERT DATA
4448
int InsertCompetencyAssessment(int adminId, int centreId, string competencyAssessmentName, int? frameworkId);
4549
bool InsertSelfAssessmentFramework(int adminId, int assessmentId, int frameworkId);
4650
int GetCompetencyCountByFrameworkId(int competencyAssessmentId, int frameworkId);
51+
52+
//DELETE DATA
53+
bool RemoveFrameworkCompetenciesFromAssessment(int competencyAssessmentId, int frameworkId);
54+
4755
}
4856
public class CompetencyAssessmentService : ICompetencyAssessmentService
4957
{
@@ -186,5 +194,28 @@ public int GetCompetencyCountByFrameworkId(int competencyAssessmentId, int frame
186194
{
187195
return competencyAssessmentDataService.GetCompetencyCountByFrameworkId(competencyAssessmentId, frameworkId);
188196
}
197+
198+
public bool RemoveFrameworkCompetenciesFromAssessment(int competencyAssessmentId, int frameworkId)
199+
{
200+
UpdateSelectCompetenciesTaskStatus(competencyAssessmentId, false, true);
201+
UpdateOptionalCompetenciesTaskStatus(competencyAssessmentId, false, true);
202+
UpdateRoleRequirementsTaskStatus(competencyAssessmentId, false, true);
203+
return competencyAssessmentDataService.RemoveFrameworkCompetenciesFromAssessment(competencyAssessmentId, frameworkId);
204+
}
205+
206+
public bool UpdateSelectCompetenciesTaskStatus(int assessmentId, bool taskStatus, bool? previousStatus)
207+
{
208+
return competencyAssessmentDataService.UpdateSelectCompetenciesTaskStatus(assessmentId, taskStatus, previousStatus);
209+
}
210+
211+
public bool UpdateOptionalCompetenciesTaskStatus(int assessmentId, bool taskStatus, bool? previousStatus)
212+
{
213+
return competencyAssessmentDataService.UpdateOptionalCompetenciesTaskStatus(assessmentId, taskStatus, previousStatus);
214+
}
215+
216+
public bool UpdateRoleRequirementsTaskStatus(int assessmentId, bool taskStatus, bool? previousStatus)
217+
{
218+
return competencyAssessmentDataService.UpdateRoleRequirementsTaskStatus(assessmentId, taskStatus, previousStatus);
219+
}
189220
}
190221
}

DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/ConfirmRemoveFrameworkSourceViewModel.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using DigitalLearningSolutions.Data.Models.CompetencyAssessments;
22
using DigitalLearningSolutions.Data.Models.Frameworks;
33
using DigitalLearningSolutions.Web.Attributes;
4-
using DocumentFormat.OpenXml.Office2010.Excel;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Threading.Tasks;
84

95
namespace DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments
106
{
@@ -13,15 +9,19 @@ public class ConfirmRemoveFrameworkSourceViewModel
139
public ConfirmRemoveFrameworkSourceViewModel() { }
1410
public ConfirmRemoveFrameworkSourceViewModel(CompetencyAssessmentBase competencyAssessmentBase, DetailFramework framework, int competencyCount)
1511
{
12+
CompetencyAssessmentId = competencyAssessmentBase.ID;
1613
CompetencyCount = competencyCount;
1714
AssessmentName = competencyAssessmentBase.CompetencyAssessmentName;
1815
FrameworkName = framework.FrameworkName;
19-
FrameworkID = framework.ID;
16+
FrameworkId = framework.ID;
17+
Vocabulary = competencyAssessmentBase.Vocabulary;
2018
}
19+
public int CompetencyAssessmentId { get; set; }
2120
public string? AssessmentName { get; set; }
2221
public string? FrameworkName { get; set; }
23-
public int FrameworkID { get; set; }
22+
public int FrameworkId { get; set; }
2423
public int CompetencyCount { get; set; }
24+
public string? Vocabulary { get; set; }
2525
[BooleanMustBeTrue(ErrorMessage = "You must confirm that you wish to remove this framework")]
2626
public bool Confirm { get; set; }
2727

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@using DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments
1+
@using DigitalLearningSolutions.Web.Helpers
2+
@using DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments
23
@model ConfirmRemoveFrameworkSourceViewModel;
34
@{
45
var errorHasOccurred = !ViewData.ModelState.IsValid;
@@ -8,40 +9,43 @@
89
<div class="nhsuk-grid-column-full">
910
@if (errorHasOccurred)
1011
{
11-
<vc:error-summary order-of-property-names="@(new[] { nameof(Model.Confirm), nameof(Model.DeleteEnrolments) })" />
12+
<vc:error-summary order-of-property-names="@(new[] { nameof(Model.Confirm) })" />
1213
}
1314

14-
<h1 class="nhsuk-heading-xl">Delete delegate group</h1>
15+
<h1 class="nhsuk-heading-xl">Remove framework source from @Model.AssessmentName</h1>
1516
</div>
1617
</div>
1718

18-
<vc:field-name-value-display display-name="Group name" field-value="@Model.FrameworkName" />
19+
<vc:field-name-value-display display-name="Framework" field-value="@Model.FrameworkName" />
1920

2021
<div class="nhsuk-grid-row">
2122
<div class="nhsuk-grid-column-full">
22-
<form class="nhsuk-u-margin-bottom-3" method="post" asp-action="ConfirmDeleteGroup">
23-
<input type="hidden" asp-for="GroupLabel" />
24-
<input type="hidden" asp-for="DelegateCount" />
25-
<input type="hidden" asp-for="CourseCount" />
26-
<input type="hidden" asp-for="ReturnPageQuery" />
27-
23+
<form class="nhsuk-u-margin-bottom-3" method="post" asp-action="RemoveFramework">
24+
<input type="hidden" asp-for="CompetencyAssessmentId" />
25+
<input type="hidden" asp-for="FrameworkId" />
26+
<input type="hidden" asp-for="FrameworkName" />
27+
<input type="hidden" asp-for="AssessmentName" />
28+
<input type="hidden" asp-for="CompetencyCount" />
29+
<input type="hidden" asp-for="Vocabulary" />
2830
<p>
29-
This group has @Model.DelegateCount delegate@(DisplayStringHelper.GetPluralitySuffix(Model.DelegateCount))
30-
and @Model.CourseCount course@(DisplayStringHelper.GetPluralitySuffix(Model.CourseCount)). Deleting this
31-
group will permanently remove all the delegates and courses from this group.
31+
This competency assessment has @Model.CompetencyCount @DisplayStringHelper.PluraliseStringIfRequired(@Model.Vocabulary.ToLower(), Model.CompetencyCount)
32+
associated with it from the framework @Model.FrameworkName. Removing this
33+
framework source will remove the @DisplayStringHelper.PluraliseStringIfRequired(@Model.Vocabulary.ToLower(), Model.CompetencyCount) from the assessment.
3234
</p>
3335

3436
<vc:single-checkbox asp-for="@nameof(Model.Confirm)"
35-
label="I am sure that I wish to delete this group and remove all delegates and courses from it."
37+
label="I am sure that I wish to remove this framework source and remove the @DisplayStringHelper.PluraliseStringIfRequired(@Model.Vocabulary.ToLower(), Model.CompetencyCount) from the assessment."
3638
hint-text="" />
3739

38-
<vc:single-checkbox asp-for="@nameof(Model.DeleteEnrolments)"
39-
label="Remove all related enrolments where course has been started but is not yet complete"
40-
hint-text="Optionally all enrolments on courses that have been started but are incomplete and are associated with the group membership can also be removed." />
41-
42-
<button class="nhsuk-button delete-button" type="submit">Delete group</button>
40+
<button class="nhsuk-button delete-button" type="submit">Remove framework source</button>
4341
</form>
44-
45-
<vc:cancel-link-with-return-page-query asp-controller="DelegateGroups" asp-action="Index" return-page-query="@Model.ReturnPageQuery" />
42+
<div class="nhsuk-back-link">
43+
<a class="nhsuk-back-link__link" asp-action="SelectFrameworkSources" asp-route-actionName="Summary" asp-route-competencyAssessmentId="@ViewContext.RouteData.Values["competencyAssessmentId"]">
44+
<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">
45+
<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>
46+
</svg>
47+
Cancel
48+
</a>
49+
</div>
4650
</div>
4751
</div>

0 commit comments

Comments
 (0)