diff --git a/DigitalLearningSolutions.Data/DataServices/CompetencyAssessmentDataService.cs b/DigitalLearningSolutions.Data/DataServices/CompetencyAssessmentDataService.cs index 80919b1730..853e2bf42e 100644 --- a/DigitalLearningSolutions.Data/DataServices/CompetencyAssessmentDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/CompetencyAssessmentDataService.cs @@ -1,6 +1,7 @@ namespace DigitalLearningSolutions.Data.DataServices { using Dapper; + using DigitalLearningSolutions.Data.Extensions; using DigitalLearningSolutions.Data.Models.CompetencyAssessments; using Microsoft.Extensions.Logging; using System; @@ -69,6 +70,7 @@ string direction public bool UpdateCompetencyAssessmentFeaturesTaskStatus(int id, bool descriptionStatus, bool providerandCategoryStatus, bool vocabularyStatus, bool workingGroupStatus, bool AllframeworkCompetenciesStatus); void UpdateSelfAssessmentFromFramework(int selfAssessmentId, int? frameworkId); + bool UpdatePrimaryFrameworkCompetencies(int assessmentId, int frameworkId); //INSERT DATA int InsertCompetencyAssessment(int adminId, int centreId, string competencyAssessmentName); @@ -877,13 +879,51 @@ FROM FrameworkCompetencies AS FC return true; } + + public bool UpdatePrimaryFrameworkCompetencies(int assessmentId, int frameworkId) + { + connection.EnsureOpen(); + using (var transaction = connection.BeginTransaction()) + { + var numberOfAffectedRows = connection.Execute( + @"UPDATE SelfAssessmentFrameworks + SET IsPrimary = 0 + WHERE (SelfAssessmentId = @assessmentId) + AND (RemovedDate IS NULL)", + new { assessmentId }, + transaction: transaction + ); + + var numberOfAffectedRow = connection.Execute( + @"UPDATE SelfAssessmentFrameworks + SET IsPrimary = 1 + WHERE (SelfAssessmentId = @assessmentId) + AND (FrameworkId = @frameworkId) + AND (RemovedDate IS NULL)", + new { assessmentId, frameworkId }, + transaction: transaction + ); + + if ((numberOfAffectedRow < 1) || (numberOfAffectedRows < 1)) + { + logger.LogWarning( + "Not updating SelfAssessmentFrameworks as db update failed. " + + $"assessmentId: {assessmentId}, frameworkId: {frameworkId}" + ); + transaction.Rollback(); + return false; + } + + transaction.Commit(); + return true; + } + } public int? GetSelfAssessmentStructure(int competencyAssessmentId) { return connection.QueryFirstOrDefault( @"SELECT 1 from dbo.SelfAssessmentStructure where selfassessmentid = @competencyAssessmentId", new { competencyAssessmentId } - ); - + ); } public IEnumerable GetCollaboratorsForCompetencyAssessmentId(int competencyAssessmentId) { diff --git a/DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs b/DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs index d31bb1d2ab..5a452adb26 100644 --- a/DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs +++ b/DigitalLearningSolutions.Web/Controllers/CompetencyAssessmentsController/CompetencyAssessments.cs @@ -692,8 +692,8 @@ public IActionResult CompetencyAssessmentSummary(int competencyAssessmentId, int public IActionResult CompetencyAssessmentSummary(CompetencyAssessmentFeaturesViewModel competency) { var data = GetcompetencyAssessmentFeaturesData(); - if (data.ID == 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 }); if (competencyAssessmentService.GetSelfAssessmentStructure(data.ID) != 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 410 }); + if (data.ID == 0) return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 }); var features = competencyAssessmentService.UpdateCompetencyAssessmentFeaturesTaskStatus(data.ID, data.DescriptionStatus, data.ProviderandCategoryStatus, @@ -709,6 +709,34 @@ public IActionResult CompetencyAssessmentSummary(CompetencyAssessmentFeaturesVie return RedirectToAction("ManageCompetencyAssessment", new { competencyAssessmentId = competency.ID, competency.FrameworkId }); } + [Route("/CompetencyAssessments/{competencyAssessmentId}/Frameworks/{frameworkId}/Make")] + public IActionResult ConfirmMaKePrimaryFramework(int frameworkId, int competencyAssessmentId) + { + var adminId = GetAdminID(); + var competencyAssessmentBase = competencyAssessmentService.GetCompetencyAssessmentBaseById(competencyAssessmentId, adminId); + var framework = frameworkService.GetFrameworkDetailByFrameworkId(frameworkId, adminId); + var model = new ConfirmMakePrimaryFrameworkViewModel(competencyAssessmentBase, framework); + return View("ConfirmMaKePrimaryFramework", model); + } + [HttpPost] + [Route("/CompetencyAssessments/{competencyAssessmentId}/Frameworks/{frameworkId}/Make")] + public IActionResult ConfirmMaKePrimaryFramework(ConfirmMakePrimaryFrameworkViewModel model) + { + if (!ModelState.IsValid) + { + return View("ConfirmMaKePrimaryFramework", model); + } + competencyAssessmentService.UpdatePrimaryFrameworkCompetencies(model.CompetencyAssessmentId, model.FrameworkId); + var features = competencyAssessmentService.UpdateCompetencyAssessmentFeaturesTaskStatus(model.CompetencyAssessmentId, + model.DescriptionStatus, + model.ProviderandCategoryStatus, + model.VocabularyStatus, + model.WorkingGroupStatus, + model.AllframeworkCompetenciesStatus); + return RedirectToAction("ManageCompetencyAssessment", new { model.CompetencyAssessmentId, model.FrameworkId }); + } + + [Route("/CompetencyAssessments/{competencyAssessmentId}/{actionName}")] public IActionResult AssessmentWorkingGroup(int competencyAssessmentId, string actionName) { @@ -787,6 +815,7 @@ public IActionResult RemoveCollaborator(int competencyAssessmentId, int id, stri return RedirectToAction("AssessmentWorkingGroup", "CompetencyAssessments", new { competencyAssessmentId, actionName = actionName }); } + private void SetcompetencyAssessmentFeaturesData(CompetencyAssessmentFeaturesViewModel data) { multiPageFormService.SetMultiPageFormData( @@ -795,7 +824,6 @@ private void SetcompetencyAssessmentFeaturesData(CompetencyAssessmentFeaturesVie TempData ); } - private CompetencyAssessmentFeaturesViewModel GetcompetencyAssessmentFeaturesData() { var data = multiPageFormService.GetMultiPageFormData( diff --git a/DigitalLearningSolutions.Web/Services/CompetencyAssessmentService.cs b/DigitalLearningSolutions.Web/Services/CompetencyAssessmentService.cs index 60f8f6118a..05859537e6 100644 --- a/DigitalLearningSolutions.Web/Services/CompetencyAssessmentService.cs +++ b/DigitalLearningSolutions.Web/Services/CompetencyAssessmentService.cs @@ -32,6 +32,7 @@ public interface ICompetencyAssessmentService int[] GetLinkedFrameworkCompetencyIds(int competencyAssessmentId, int frameworkId); CompetencyAssessmentFeatures? GetCompetencyAssessmentFeaturesTaskStatus(int competencyAssessmentId); int? GetSelfAssessmentStructure(int competencyAssessmentId); + //UPDATE DATA bool UpdateCompetencyAssessmentName(int competencyAssessmentId, int adminId, string competencyAssessmentName); bool UpdateCompetencyRoleProfileLinks(int competencyAssessmentId, int adminId, int? professionalGroupId, int? subGroupId, int? roleId); @@ -58,6 +59,7 @@ string direction bool UpdateCompetencyAssessmentFeaturesTaskStatus(int id, bool descriptionStatus, bool providerandCategoryStatus, bool vocabularyStatus, bool workingGroupStatus, bool AllframeworkCompetenciesStatus); void UpdateSelfAssessmentFromFramework(int selfAssessmentId, int? frameworkId); + bool UpdatePrimaryFrameworkCompetencies(int assessmentId, int frameworkId); //INSERT DATA int InsertCompetencyAssessment(int adminId, int centreId, string competencyAssessmentName, int? frameworkId); @@ -295,6 +297,11 @@ public void UpdateSelfAssessmentFromFramework(int selfAssessmentId, int? framewo { competencyAssessmentDataService.UpdateSelfAssessmentFromFramework(selfAssessmentId, frameworkId); } + public bool UpdatePrimaryFrameworkCompetencies(int assessmentId, int frameworkId) + { + return competencyAssessmentDataService.UpdatePrimaryFrameworkCompetencies(assessmentId, frameworkId); + } + public int? GetSelfAssessmentStructure(int competencyAssessmentId) { return competencyAssessmentDataService.GetSelfAssessmentStructure(competencyAssessmentId); @@ -314,6 +321,7 @@ public void RemoveCollaboratorFromCompetencyAssessment(int competencyAssessmentI public CompetencyAssessmentCollaboratorNotification? GetCollaboratorNotification(int id, int invitedByAdminId) { return competencyAssessmentDataService.GetCollaboratorNotification(id, invitedByAdminId); + } } } diff --git a/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/ConfirmChangePrimaryFrameworkViewModel.cs b/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/ConfirmChangePrimaryFrameworkViewModel.cs new file mode 100644 index 0000000000..9c24ba5640 --- /dev/null +++ b/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/ConfirmChangePrimaryFrameworkViewModel.cs @@ -0,0 +1,28 @@ +using DigitalLearningSolutions.Data.Models.CompetencyAssessments; +using DigitalLearningSolutions.Data.Models.Frameworks; +using DigitalLearningSolutions.Web.Attributes; + +namespace DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments +{ + public class ConfirmChangePrimaryFrameworkViewModel + { + public ConfirmChangePrimaryFrameworkViewModel() + {} + public ConfirmChangePrimaryFrameworkViewModel(CompetencyAssessmentBase competencyAssessmentBase, DetailFramework framework) + { + CompetencyAssessmentId = competencyAssessmentBase.ID; + AssessmentName = competencyAssessmentBase.CompetencyAssessmentName; + FrameworkName = framework.FrameworkName; + FrameworkId = framework.ID; + Vocabulary = competencyAssessmentBase.Vocabulary; + } + public int CompetencyAssessmentId { get; set; } + public int UserRole { get; set; } + public string? AssessmentName { get; set; } + public string? FrameworkName { get; set; } + public int FrameworkId { get; set; } + public string? Vocabulary { get; set; } + [BooleanMustBeTrue(ErrorMessage = "You must confirm that you wish to change the primary framework")] + public bool Confirm { get; set; } + } +} diff --git a/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/ConfirmMakePrimaryFrameworkViewModel.cs b/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/ConfirmMakePrimaryFrameworkViewModel.cs new file mode 100644 index 0000000000..bc069c865a --- /dev/null +++ b/DigitalLearningSolutions.Web/ViewModels/CompetencyAssessments/ConfirmMakePrimaryFrameworkViewModel.cs @@ -0,0 +1,33 @@ +using DigitalLearningSolutions.Data.Models.CompetencyAssessments; +using DigitalLearningSolutions.Data.Models.Frameworks; +using System.ComponentModel.DataAnnotations; + +namespace DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments +{ + public class ConfirmMakePrimaryFrameworkViewModel + { + public ConfirmMakePrimaryFrameworkViewModel() + {} + public ConfirmMakePrimaryFrameworkViewModel(CompetencyAssessmentBase competencyAssessmentBase, DetailFramework framework) + { + CompetencyAssessmentId = competencyAssessmentBase.ID; + AssessmentName = competencyAssessmentBase.CompetencyAssessmentName; + FrameworkName = framework.FrameworkName; + FrameworkId = framework.ID; + Vocabulary = competencyAssessmentBase.Vocabulary; + } + public int CompetencyAssessmentId { get; set; } + public int UserRole { get; set; } + public string? AssessmentName { get; set; } + public string? FrameworkName { get; set; } + public int FrameworkId { get; set; } + public string? Vocabulary { get; set; } + [Required(ErrorMessage = "You need to confirm that you want to make this the primary framework")] + public bool? Confirm { get; set; } + public bool DescriptionStatus { get; set; } + public bool ProviderandCategoryStatus { get; set; } + public bool VocabularyStatus { get; set; } + public bool WorkingGroupStatus { get; set; } + public bool AllframeworkCompetenciesStatus { get; set; } + } +} diff --git a/DigitalLearningSolutions.Web/Views/CompetencyAssessments/ConfirmChangePrimaryFramework.cshtml b/DigitalLearningSolutions.Web/Views/CompetencyAssessments/ConfirmChangePrimaryFramework.cshtml new file mode 100644 index 0000000000..3ef1327b76 --- /dev/null +++ b/DigitalLearningSolutions.Web/Views/CompetencyAssessments/ConfirmChangePrimaryFramework.cshtml @@ -0,0 +1,43 @@ +@using DigitalLearningSolutions.Web.Helpers +@using DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments +@model ConfirmChangePrimaryFrameworkViewModel; +@{ + var errorHasOccurred = !ViewData.ModelState.IsValid; + ViewData["Title"] = "Competency Assessments - Change primary framework"; +} +
+
+ @if (errorHasOccurred) + { + + } + +

Change primary framework to @Model.FrameworkName

+
+
+
+
+
+ + + + + + + + + + + + +
+
diff --git a/DigitalLearningSolutions.Web/Views/CompetencyAssessments/ConfirmMakePrimaryFramework.cshtml b/DigitalLearningSolutions.Web/Views/CompetencyAssessments/ConfirmMakePrimaryFramework.cshtml new file mode 100644 index 0000000000..1d70a73cf7 --- /dev/null +++ b/DigitalLearningSolutions.Web/Views/CompetencyAssessments/ConfirmMakePrimaryFramework.cshtml @@ -0,0 +1,121 @@ +@using DigitalLearningSolutions.Web.Helpers +@using DigitalLearningSolutions.Web.ViewModels.CompetencyAssessments +@model ConfirmMakePrimaryFrameworkViewModel; + +@{ + var errorHasOccurred = !ViewData.ModelState.IsValid && ViewData.ModelState.ContainsKey(nameof(Model.Confirm)); + ViewData["Title"] = "Competency Assessments - make primary framework"; +} + +
+
+ @if (errorHasOccurred) + { + + } +

Make @Model.FrameworkName primary framework

+
+
+ +
+
+
+ +
+ + Which features of the framework do you want to copy into this @Model.FrameworkName framework? + +
+
+ + +
+ The framework description will be copied into the competency assessment description. +
+
+
+
+
+ + +
+ The framework branding (provider and category) will be copied. +
+
+
+
+
+ + +
+ The framework vocabulary (such as proficiency, competency, or capability) will be copied. +
+
+
+ +
+
+ + +
+ Contributors and reviewers from the framework will be copied. +
+
+
+ +
+
+ + +
+ All competencies in the framework will be copied. +
+
+
+
+
+ + +
+ + + +
+
+ @* Hidden fields *@ + + + + + + + + + + +
+ + +
+
diff --git a/DigitalLearningSolutions.Web/Views/CompetencyAssessments/SelectFrameworkSources.cshtml b/DigitalLearningSolutions.Web/Views/CompetencyAssessments/SelectFrameworkSources.cshtml index e3a4efe516..b7ca7048af 100644 --- a/DigitalLearningSolutions.Web/Views/CompetencyAssessments/SelectFrameworkSources.cshtml +++ b/DigitalLearningSolutions.Web/Views/CompetencyAssessments/SelectFrameworkSources.cshtml @@ -21,6 +21,13 @@ } +

Select framework sources for @Model.CompetencyAssessmentName

@@ -34,9 +41,13 @@ @Model.PrimaryFramework.FrameworkName
- - Remove @Model.PrimaryFramework.FrameworkName - +
} @@ -52,9 +63,23 @@ @Model.AdditionalFrameworks.ElementAt(i).FrameworkName
- - Remove @Model.AdditionalFrameworks.ElementAt(i).FrameworkName - +
}