Skip to content

Commit ca0b53d

Browse files
authored
Merge pull request #3382 from TechnologyEnhancedLearning/Develop/Features/TD-5563-Allowuserstochangetheprimaryframework
TD-5563 Allow users to change the primary framework
2 parents 2eaa6b2 + bc4ee7e commit ca0b53d

File tree

8 files changed

+336
-10
lines changed

8 files changed

+336
-10
lines changed

DigitalLearningSolutions.Data/DataServices/CompetencyAssessmentDataService.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace DigitalLearningSolutions.Data.DataServices
22
{
33
using Dapper;
4+
using DigitalLearningSolutions.Data.Extensions;
45
using DigitalLearningSolutions.Data.Models.CompetencyAssessments;
56
using Microsoft.Extensions.Logging;
67
using System;
@@ -69,6 +70,7 @@ string direction
6970
public bool UpdateCompetencyAssessmentFeaturesTaskStatus(int id, bool descriptionStatus, bool providerandCategoryStatus, bool vocabularyStatus,
7071
bool workingGroupStatus, bool AllframeworkCompetenciesStatus);
7172
void UpdateSelfAssessmentFromFramework(int selfAssessmentId, int? frameworkId);
73+
bool UpdatePrimaryFrameworkCompetencies(int assessmentId, int frameworkId);
7274

7375
//INSERT DATA
7476
int InsertCompetencyAssessment(int adminId, int centreId, string competencyAssessmentName);
@@ -877,13 +879,51 @@ FROM FrameworkCompetencies AS FC
877879

878880
return true;
879881
}
882+
883+
public bool UpdatePrimaryFrameworkCompetencies(int assessmentId, int frameworkId)
884+
{
885+
connection.EnsureOpen();
886+
using (var transaction = connection.BeginTransaction())
887+
{
888+
var numberOfAffectedRows = connection.Execute(
889+
@"UPDATE SelfAssessmentFrameworks
890+
SET IsPrimary = 0
891+
WHERE (SelfAssessmentId = @assessmentId)
892+
AND (RemovedDate IS NULL)",
893+
new { assessmentId },
894+
transaction: transaction
895+
);
896+
897+
var numberOfAffectedRow = connection.Execute(
898+
@"UPDATE SelfAssessmentFrameworks
899+
SET IsPrimary = 1
900+
WHERE (SelfAssessmentId = @assessmentId)
901+
AND (FrameworkId = @frameworkId)
902+
AND (RemovedDate IS NULL)",
903+
new { assessmentId, frameworkId },
904+
transaction: transaction
905+
);
906+
907+
if ((numberOfAffectedRow < 1) || (numberOfAffectedRows < 1))
908+
{
909+
logger.LogWarning(
910+
"Not updating SelfAssessmentFrameworks as db update failed. " +
911+
$"assessmentId: {assessmentId}, frameworkId: {frameworkId}"
912+
);
913+
transaction.Rollback();
914+
return false;
915+
}
916+
917+
transaction.Commit();
918+
return true;
919+
}
920+
}
880921
public int? GetSelfAssessmentStructure(int competencyAssessmentId)
881922
{
882923
return connection.QueryFirstOrDefault<int>(
883924
@"SELECT 1 from dbo.SelfAssessmentStructure where selfassessmentid = @competencyAssessmentId",
884925
new { competencyAssessmentId }
885-
);
886-
926+
);
887927
}
888928
public IEnumerable<CompetencyAssessmentCollaboratorDetail> GetCollaboratorsForCompetencyAssessmentId(int competencyAssessmentId)
889929
{

DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,8 @@ public IActionResult CompetencyAssessmentSummary(int competencyAssessmentId, int
692692
public IActionResult CompetencyAssessmentSummary(CompetencyAssessmentFeaturesViewModel competency)
693693
{
694694
var data = GetcompetencyAssessmentFeaturesData();
695-
if (data.ID == 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 });
696695
if (competencyAssessmentService.GetSelfAssessmentStructure(data.ID) != 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 410 });
696+
if (data.ID == 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 });
697697
var features = competencyAssessmentService.UpdateCompetencyAssessmentFeaturesTaskStatus(data.ID,
698698
data.DescriptionStatus,
699699
data.ProviderandCategoryStatus,
@@ -709,6 +709,34 @@ public IActionResult CompetencyAssessmentSummary(CompetencyAssessmentFeaturesVie
709709
return RedirectToAction("ManageCompetencyAssessment", new { competencyAssessmentId = competency.ID, competency.FrameworkId });
710710
}
711711

712+
[Route("/CompetencyAssessments/{competencyAssessmentId}/Frameworks/{frameworkId}/Make")]
713+
public IActionResult ConfirmMaKePrimaryFramework(int frameworkId, int competencyAssessmentId)
714+
{
715+
var adminId = GetAdminID();
716+
var competencyAssessmentBase = competencyAssessmentService.GetCompetencyAssessmentBaseById(competencyAssessmentId, adminId);
717+
var framework = frameworkService.GetFrameworkDetailByFrameworkId(frameworkId, adminId);
718+
var model = new ConfirmMakePrimaryFrameworkViewModel(competencyAssessmentBase, framework);
719+
return View("ConfirmMaKePrimaryFramework", model);
720+
}
721+
[HttpPost]
722+
[Route("/CompetencyAssessments/{competencyAssessmentId}/Frameworks/{frameworkId}/Make")]
723+
public IActionResult ConfirmMaKePrimaryFramework(ConfirmMakePrimaryFrameworkViewModel model)
724+
{
725+
if (!ModelState.IsValid)
726+
{
727+
return View("ConfirmMaKePrimaryFramework", model);
728+
}
729+
competencyAssessmentService.UpdatePrimaryFrameworkCompetencies(model.CompetencyAssessmentId, model.FrameworkId);
730+
var features = competencyAssessmentService.UpdateCompetencyAssessmentFeaturesTaskStatus(model.CompetencyAssessmentId,
731+
model.DescriptionStatus,
732+
model.ProviderandCategoryStatus,
733+
model.VocabularyStatus,
734+
model.WorkingGroupStatus,
735+
model.AllframeworkCompetenciesStatus);
736+
return RedirectToAction("ManageCompetencyAssessment", new { model.CompetencyAssessmentId, model.FrameworkId });
737+
}
738+
739+
712740
[Route("/CompetencyAssessments/{competencyAssessmentId}/{actionName}")]
713741
public IActionResult AssessmentWorkingGroup(int competencyAssessmentId, string actionName)
714742
{
@@ -787,6 +815,7 @@ public IActionResult RemoveCollaborator(int competencyAssessmentId, int id, stri
787815
return RedirectToAction("AssessmentWorkingGroup", "CompetencyAssessments", new { competencyAssessmentId, actionName = actionName });
788816
}
789817

818+
790819
private void SetcompetencyAssessmentFeaturesData(CompetencyAssessmentFeaturesViewModel data)
791820
{
792821
multiPageFormService.SetMultiPageFormData(
@@ -795,7 +824,6 @@ private void SetcompetencyAssessmentFeaturesData(CompetencyAssessmentFeaturesVie
795824
TempData
796825
);
797826
}
798-
799827
private CompetencyAssessmentFeaturesViewModel GetcompetencyAssessmentFeaturesData()
800828
{
801829
var data = multiPageFormService.GetMultiPageFormData<CompetencyAssessmentFeaturesViewModel>(

DigitalLearningSolutions.Web/Services/CompetencyAssessmentService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public interface ICompetencyAssessmentService
3232
int[] GetLinkedFrameworkCompetencyIds(int competencyAssessmentId, int frameworkId);
3333
CompetencyAssessmentFeatures? GetCompetencyAssessmentFeaturesTaskStatus(int competencyAssessmentId);
3434
int? GetSelfAssessmentStructure(int competencyAssessmentId);
35+
3536
//UPDATE DATA
3637
bool UpdateCompetencyAssessmentName(int competencyAssessmentId, int adminId, string competencyAssessmentName);
3738
bool UpdateCompetencyRoleProfileLinks(int competencyAssessmentId, int adminId, int? professionalGroupId, int? subGroupId, int? roleId);
@@ -58,6 +59,7 @@ string direction
5859
bool UpdateCompetencyAssessmentFeaturesTaskStatus(int id, bool descriptionStatus, bool providerandCategoryStatus, bool vocabularyStatus,
5960
bool workingGroupStatus, bool AllframeworkCompetenciesStatus);
6061
void UpdateSelfAssessmentFromFramework(int selfAssessmentId, int? frameworkId);
62+
bool UpdatePrimaryFrameworkCompetencies(int assessmentId, int frameworkId);
6163

6264
//INSERT DATA
6365
int InsertCompetencyAssessment(int adminId, int centreId, string competencyAssessmentName, int? frameworkId);
@@ -295,6 +297,11 @@ public void UpdateSelfAssessmentFromFramework(int selfAssessmentId, int? framewo
295297
{
296298
competencyAssessmentDataService.UpdateSelfAssessmentFromFramework(selfAssessmentId, frameworkId);
297299
}
300+
public bool UpdatePrimaryFrameworkCompetencies(int assessmentId, int frameworkId)
301+
{
302+
return competencyAssessmentDataService.UpdatePrimaryFrameworkCompetencies(assessmentId, frameworkId);
303+
}
304+
298305
public int? GetSelfAssessmentStructure(int competencyAssessmentId)
299306
{
300307
return competencyAssessmentDataService.GetSelfAssessmentStructure(competencyAssessmentId);
@@ -314,6 +321,7 @@ public void RemoveCollaboratorFromCompetencyAssessment(int competencyAssessmentI
314321
public CompetencyAssessmentCollaboratorNotification? GetCollaboratorNotification(int id, int invitedByAdminId)
315322
{
316323
return competencyAssessmentDataService.GetCollaboratorNotification(id, invitedByAdminId);
324+
317325
}
318326
}
319327
}
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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using DigitalLearningSolutions.Data.Models.CompetencyAssessments;
2+
using DigitalLearningSolutions.Data.Models.Frameworks;
3+
using System.ComponentModel.DataAnnotations;
4+
5+
namespace DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments
6+
{
7+
public class ConfirmMakePrimaryFrameworkViewModel
8+
{
9+
public ConfirmMakePrimaryFrameworkViewModel()
10+
{}
11+
public ConfirmMakePrimaryFrameworkViewModel(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+
[Required(ErrorMessage = "You need to confirm that you want to make this the primary framework")]
26+
public bool? Confirm { get; set; }
27+
public bool DescriptionStatus { get; set; }
28+
public bool ProviderandCategoryStatus { get; set; }
29+
public bool VocabularyStatus { get; set; }
30+
public bool WorkingGroupStatus { get; set; }
31+
public bool AllframeworkCompetenciesStatus { get; set; }
32+
}
33+
}
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>

0 commit comments

Comments
 (0)