Skip to content

Commit 48a257c

Browse files
TD-5563 Allow users to change the primary framework
1 parent 35c8e07 commit 48a257c

File tree

6 files changed

+151
-20
lines changed

6 files changed

+151
-20
lines changed

DigitalLearningSolutions.Data/DataServices/CompetencyAssessmentDataService.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public interface ICompetencyAssessmentDataService
3434
IEnumerable<LinkedFramework> GetLinkedFrameworksForCompetencyAssessment(int competencyAssessmentId);
3535
int[] GetLinkedFrameworkCompetencyIds(int competencyAssessmentId, int frameworkId);
3636
CompetencyAssessmentFeatures? GetCompetencyAssessmentFeaturesTaskStatus(int competencyAssessmentId);
37-
int? GetSelfAssessmentStructure(int competencyAssessmentId);
3837

3938
//UPDATE DATA
4039
bool UpdateCompetencyAssessmentName(int competencyAssessmentId, int adminId, string competencyAssessmentName);
@@ -68,6 +67,7 @@ string direction
6867
public bool UpdateCompetencyAssessmentFeaturesTaskStatus(int id, bool descriptionStatus, bool providerandCategoryStatus, bool vocabularyStatus,
6968
bool workingGroupStatus, bool AllframeworkCompetenciesStatus);
7069
void UpdateSelfAssessmentFromFramework(int selfAssessmentId, int? frameworkId);
70+
bool UpdatePrimaryFrameworkCompetencies(int assessmentId, int frameworkId);
7171

7272
//INSERT DATA
7373
int InsertCompetencyAssessment(int adminId, int centreId, string competencyAssessmentName);
@@ -857,13 +857,25 @@ FROM FrameworkCompetencies AS FC
857857

858858
return true;
859859
}
860-
public int? GetSelfAssessmentStructure(int competencyAssessmentId)
860+
public bool UpdatePrimaryFrameworkCompetencies(int assessmentId, int frameworkId)
861861
{
862-
return connection.QueryFirstOrDefault<int>(
863-
@"SELECT 1 from dbo.SelfAssessmentStructure where selfassessmentid = @competencyAssessmentId",
864-
new { competencyAssessmentId }
862+
var numberOfAffectedRows = connection.Execute(
863+
@"UPDATE SelfAssessmentFrameworks SET IsPrimary = 0 WHERE (SelfAssessmentId = @assessmentId) AND (RemovedDate IS NULL)",
864+
new { assessmentId, frameworkId }
865865
);
866-
866+
var numberOfAffectedRow = connection.Execute(
867+
@"UPDATE SelfAssessmentFrameworks SET IsPrimary = 1 WHERE (SelfAssessmentId = @assessmentId) AND (FrameworkId = @frameworkId ) AND (RemovedDate IS NULL)",
868+
new { assessmentId, frameworkId }
869+
);
870+
if (numberOfAffectedRow < 1)
871+
{
872+
logger.LogWarning(
873+
"Not updating SelfAssessmentFrameworks as db update failed. " +
874+
$"assessmentId: {assessmentId}, frameworkId: {frameworkId}"
875+
);
876+
return false;
877+
}
878+
return true;
867879
}
868880
}
869881
}

DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ public IActionResult CompetencyAssessmentFeatures(CompetencyAssessmentFeaturesVi
680680
[Route("/CompetencyAssessments/Framework/{frameworkId}/{competencyAssessmentId}/Summary")]
681681
public IActionResult CompetencyAssessmentSummary(int competencyAssessmentId, int? frameworkId = null)
682682
{
683-
if (competencyAssessmentService.GetSelfAssessmentStructure(competencyAssessmentId) != 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 410 });
683+
684684
if (competencyAssessmentId == 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 });
685685
var data = GetcompetencyAssessmentFeaturesData();
686686
if (data == null) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 500 });
@@ -693,7 +693,6 @@ public IActionResult CompetencyAssessmentSummary(CompetencyAssessmentFeaturesVie
693693
{
694694
var data = GetcompetencyAssessmentFeaturesData();
695695
if (data.ID == 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 });
696-
if (competencyAssessmentService.GetSelfAssessmentStructure(data.ID) != 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 410 });
697696
var features = competencyAssessmentService.UpdateCompetencyAssessmentFeaturesTaskStatus(data.ID,
698697
data.DescriptionStatus,
699698
data.ProviderandCategoryStatus,
@@ -708,7 +707,31 @@ public IActionResult CompetencyAssessmentSummary(CompetencyAssessmentFeaturesVie
708707
TempData.Clear();
709708
return RedirectToAction("ManageCompetencyAssessment", new { competencyAssessmentId = competency.ID, competency.FrameworkId });
710709
}
711-
710+
[Route("/CompetencyAssessments/{competencyAssessmentId}/Frameworks/{frameworkId}/Change")]
711+
public IActionResult ConfirmChangePrimaryFramework(int frameworkId, int competencyAssessmentId)
712+
{
713+
var adminId = GetAdminID();
714+
var competencyAssessmentBase = competencyAssessmentService.GetCompetencyAssessmentBaseById(competencyAssessmentId, adminId);
715+
var framework = frameworkService.GetFrameworkDetailByFrameworkId(frameworkId, adminId);
716+
var model = new ConfirmChangePrimaryFrameworkViewModel(competencyAssessmentBase, framework);
717+
return View("ConfirmChangePrimaryFramework", model);
718+
}
719+
[HttpPost]
720+
[Route("/CompetencyAssessments/{competencyAssessmentId}/Frameworks/{frameworkId}/Change")]
721+
public IActionResult ConfirmChangePrimaryFramework(ConfirmChangePrimaryFrameworkViewModel model)
722+
{
723+
if (!ModelState.IsValid)
724+
{
725+
return View("ConfirmChangePrimaryFramework", model);
726+
}
727+
competencyAssessmentService.UpdatePrimaryFrameworkCompetencies(model.CompetencyAssessmentId, model.FrameworkId);
728+
var baseModel = new CompetencyAssessmentFeaturesViewModel(model.CompetencyAssessmentId,
729+
model.FrameworkName,
730+
model.UserRole,
731+
model.FrameworkId);
732+
SetcompetencyAssessmentFeaturesData(baseModel);
733+
return RedirectToAction("CompetencyAssessmentFeatures", new { model.CompetencyAssessmentId, model.FrameworkId });
734+
}
712735
private void SetcompetencyAssessmentFeaturesData(CompetencyAssessmentFeaturesViewModel data)
713736
{
714737
multiPageFormService.SetMultiPageFormData(
@@ -717,7 +740,6 @@ private void SetcompetencyAssessmentFeaturesData(CompetencyAssessmentFeaturesVie
717740
TempData
718741
);
719742
}
720-
721743
private CompetencyAssessmentFeaturesViewModel GetcompetencyAssessmentFeaturesData()
722744
{
723745
var data = multiPageFormService.GetMultiPageFormData<CompetencyAssessmentFeaturesViewModel>(

DigitalLearningSolutions.Web/Services/CompetencyAssessmentService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface ICompetencyAssessmentService
3131

3232
int[] GetLinkedFrameworkCompetencyIds(int competencyAssessmentId, int frameworkId);
3333
CompetencyAssessmentFeatures? GetCompetencyAssessmentFeaturesTaskStatus(int competencyAssessmentId);
34-
int? GetSelfAssessmentStructure(int competencyAssessmentId);
34+
3535
//UPDATE DATA
3636
bool UpdateCompetencyAssessmentName(int competencyAssessmentId, int adminId, string competencyAssessmentName);
3737
bool UpdateCompetencyRoleProfileLinks(int competencyAssessmentId, int adminId, int? professionalGroupId, int? subGroupId, int? roleId);
@@ -57,6 +57,7 @@ string direction
5757
bool UpdateCompetencyAssessmentFeaturesTaskStatus(int id, bool descriptionStatus, bool providerandCategoryStatus, bool vocabularyStatus,
5858
bool workingGroupStatus, bool AllframeworkCompetenciesStatus);
5959
void UpdateSelfAssessmentFromFramework(int selfAssessmentId, int? frameworkId);
60+
bool UpdatePrimaryFrameworkCompetencies(int assessmentId, int frameworkId);
6061

6162
//INSERT DATA
6263
int InsertCompetencyAssessment(int adminId, int centreId, string competencyAssessmentName, int? frameworkId);
@@ -286,9 +287,9 @@ public void UpdateSelfAssessmentFromFramework(int selfAssessmentId, int? framewo
286287
{
287288
competencyAssessmentDataService.UpdateSelfAssessmentFromFramework(selfAssessmentId, frameworkId);
288289
}
289-
public int? GetSelfAssessmentStructure(int competencyAssessmentId)
290+
public bool UpdatePrimaryFrameworkCompetencies(int assessmentId, int frameworkId)
290291
{
291-
return competencyAssessmentDataService.GetSelfAssessmentStructure(competencyAssessmentId);
292-
}
292+
return competencyAssessmentDataService.UpdatePrimaryFrameworkCompetencies(assessmentId, frameworkId);
293293
}
294+
}
294295
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using DigitalLearningSolutions.Data.Models.CompetencyAssessments;
2+
using DigitalLearningSolutions.Data.Models.Frameworks;
3+
using DigitalLearningSolutions.Web.Attributes;
4+
5+
namespace DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments
6+
{
7+
public class ConfirmChangePrimaryFrameworkViewModel
8+
{
9+
public ConfirmChangePrimaryFrameworkViewModel()
10+
{}
11+
public ConfirmChangePrimaryFrameworkViewModel(CompetencyAssessmentBase competencyAssessmentBase, DetailFramework framework)
12+
{
13+
CompetencyAssessmentId = competencyAssessmentBase.ID;
14+
AssessmentName = competencyAssessmentBase.CompetencyAssessmentName;
15+
FrameworkName = framework.FrameworkName;
16+
FrameworkId = framework.ID;
17+
Vocabulary = competencyAssessmentBase.Vocabulary;
18+
}
19+
public int CompetencyAssessmentId { get; set; }
20+
public int UserRole { get; set; }
21+
public string? AssessmentName { get; set; }
22+
public string? FrameworkName { get; set; }
23+
public int FrameworkId { get; set; }
24+
public string? Vocabulary { get; set; }
25+
[BooleanMustBeTrue(ErrorMessage = "You must confirm that you wish to change the primary framework")]
26+
public bool Confirm { get; set; }
27+
}
28+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@using DigitalLearningSolutions.Web.Helpers
2+
@using DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments
3+
@model ConfirmChangePrimaryFrameworkViewModel;
4+
@{
5+
var errorHasOccurred = !ViewData.ModelState.IsValid;
6+
ViewData["Title"] = "Competency Assessments - Change primary framework";
7+
}
8+
<div class="nhsuk-grid-row">
9+
<div class="nhsuk-grid-column-full">
10+
@if (errorHasOccurred)
11+
{
12+
<vc:error-summary order-of-property-names="@(new[] { nameof(Model.Confirm) })" />
13+
}
14+
15+
<h1 class="nhsuk-heading-xl">Change primary framework to @Model.FrameworkName</h1>
16+
</div>
17+
</div>
18+
<div class="nhsuk-grid-row">
19+
<div class="nhsuk-grid-column-full">
20+
<form class="nhsuk-u-margin-bottom-3" method="post" asp-action="ConfirmChangePrimaryFramework">
21+
<input type="hidden" asp-for="CompetencyAssessmentId" />
22+
<input type="hidden" asp-for="FrameworkId" />
23+
<input type="hidden" asp-for="FrameworkName" />
24+
<input type="hidden" asp-for="AssessmentName" />
25+
<input type="hidden" asp-for="UserRole" />
26+
<input type="hidden" asp-for="Vocabulary" />
27+
28+
<vc:single-checkbox asp-for="@nameof(Model.Confirm)"
29+
label="I am sure that I wish to change the primary framework to @Model.FrameworkName "
30+
hint-text="" />
31+
32+
<button class="nhsuk-button" type="submit">Change primary framework</button>
33+
</form>
34+
<div class="nhsuk-back-link">
35+
<a class="nhsuk-back-link__link" asp-action="SelectFrameworkSources" asp-route-actionName="Summary" asp-route-competencyAssessmentId="@ViewContext.RouteData.Values["competencyAssessmentId"]">
36+
<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">
37+
<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>
38+
</svg>
39+
Cancel
40+
</a>
41+
</div>
42+
</div>
43+
</div>

DigitalLearningSolutions.Web/Views/CompetencyAssessments/SelectFrameworkSources.cshtml

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
</div>
2222
</nav>
2323
}
24+
<style>
25+
.left-align-actions {
26+
white-space: nowrap;
27+
display: inline-flex;
28+
gap: 1rem;
29+
}
30+
</style>
2431

2532
<h1>Select framework sources for @Model.CompetencyAssessmentName</h1>
2633
<dl class="nhsuk-summary-list">
@@ -34,9 +41,13 @@
3441
@Model.PrimaryFramework.FrameworkName
3542
</dd>
3643
<dd class="nhsuk-summary-list__actions">
37-
<a asp-action="RemoveFramework" asp-route-frameworkId="@Model.PrimaryFramework.ID" asp-route-competencyAssessmentId="@ViewContext.RouteData.Values["competencyAssessmentId"]">
38-
Remove<span class="nhsuk-u-visually-hidden"> @Model.PrimaryFramework.FrameworkName</span>
39-
</a>
44+
<ul class="nhsuk-summary-list__actions-list left-align-actions">
45+
<li class="nhsuk-summary-list__actions-list-item">
46+
<a asp-action="RemoveFramework" asp-route-frameworkId="@Model.PrimaryFramework.ID" asp-route-competencyAssessmentId="@ViewContext.RouteData.Values["competencyAssessmentId"]">
47+
Remove<span class="nhsuk-u-visually-hidden"> @Model.PrimaryFramework.FrameworkName</span>
48+
</a>
49+
</li>
50+
</ul>
4051
</dd>
4152
</div>
4253
}
@@ -52,9 +63,23 @@
5263
@Model.AdditionalFrameworks.ElementAt(i).FrameworkName
5364
</dd>
5465
<dd class="nhsuk-summary-list__actions">
55-
<a asp-action="RemoveFramework" asp-route-frameworkId="@Model.AdditionalFrameworks.ElementAt(i).ID" asp-route-competencyAssessmentId="@ViewContext.RouteData.Values["competencyAssessmentId"]">
56-
Remove<span class="nhsuk-u-visually-hidden"> @Model.AdditionalFrameworks.ElementAt(i).FrameworkName</span>
57-
</a>
66+
<ul class="nhsuk-summary-list__actions-list nhsuk-summary-list__actions-list--inline left-align-actions">
67+
<li class="nhsuk-summary-list__actions-list-item">
68+
<a asp-action="RemoveFramework"
69+
asp-route-frameworkId="@Model.AdditionalFrameworks.ElementAt(i).ID"
70+
asp-route-competencyAssessmentId="@ViewContext.RouteData.Values["competencyAssessmentId"]">
71+
Remove <span class="nhsuk-u-visually-hidden">@Model.AdditionalFrameworks.ElementAt(i).FrameworkName</span>
72+
</a>
73+
</li>
74+
<li class="nhsuk-summary-list__actions-list-item">
75+
<a asp-action="ConfirmChangePrimaryFramework"
76+
asp-route-frameworkId="@Model.AdditionalFrameworks.ElementAt(i).ID"
77+
asp-route-competencyAssessmentId="@ViewContext.RouteData.Values["competencyAssessmentId"]">
78+
Change primary <span class="nhsuk-u-visually-hidden">@Model.AdditionalFrameworks.ElementAt(i).FrameworkName</span>
79+
</a>
80+
</li>
81+
82+
</ul>
5883
</dd>
5984
</div>
6085
}

0 commit comments

Comments
 (0)