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
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<int>(
@"SELECT 1 from dbo.SelfAssessmentStructure where selfassessmentid = @competencyAssessmentId",
new { competencyAssessmentId }
);

);
}
public IEnumerable<CompetencyAssessmentCollaboratorDetail> GetCollaboratorsForCompetencyAssessmentId(int competencyAssessmentId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
{
Expand Down Expand Up @@ -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(
Expand All @@ -795,7 +824,6 @@ private void SetcompetencyAssessmentFeaturesData(CompetencyAssessmentFeaturesVie
TempData
);
}

private CompetencyAssessmentFeaturesViewModel GetcompetencyAssessmentFeaturesData()
{
var data = multiPageFormService.GetMultiPageFormData<CompetencyAssessmentFeaturesViewModel>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -314,6 +321,7 @@ public void RemoveCollaboratorFromCompetencyAssessment(int competencyAssessmentI
public CompetencyAssessmentCollaboratorNotification? GetCollaboratorNotification(int id, int invitedByAdminId)
{
return competencyAssessmentDataService.GetCollaboratorNotification(id, invitedByAdminId);

}
}
}
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -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";
}
<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-full">
@if (errorHasOccurred)
{
<vc:error-summary order-of-property-names="@(new[] { nameof(Model.Confirm) })" />
}

<h1 class="nhsuk-heading-xl">Change primary framework to @Model.FrameworkName</h1>
</div>
</div>
<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-full">
<form class="nhsuk-u-margin-bottom-3" method="post" asp-action="ConfirmChangePrimaryFramework">
<input type="hidden" asp-for="CompetencyAssessmentId" />
<input type="hidden" asp-for="FrameworkId" />
<input type="hidden" asp-for="FrameworkName" />
<input type="hidden" asp-for="AssessmentName" />
<input type="hidden" asp-for="UserRole" />
<input type="hidden" asp-for="Vocabulary" />

<vc:single-checkbox asp-for="@nameof(Model.Confirm)"
label="I am sure that I wish to change the primary framework to @Model.FrameworkName "
hint-text="" />

<button class="nhsuk-button" type="submit">Change primary framework</button>
</form>
<div class="nhsuk-back-link">
<a class="nhsuk-back-link__link" asp-action="SelectFrameworkSources" asp-route-actionName="Summary" asp-route-competencyAssessmentId="@ViewContext.RouteData.Values["competencyAssessmentId"]">
<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>
Cancel
</a>
</div>
</div>
</div>
Loading
Loading