diff --git a/DigitalLearningSolutions.Data/DataServices/CompetencyLearningResourcesDataService.cs b/DigitalLearningSolutions.Data/DataServices/CompetencyLearningResourcesDataService.cs index 323188bf45..f00b2b1a71 100644 --- a/DigitalLearningSolutions.Data/DataServices/CompetencyLearningResourcesDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/CompetencyLearningResourcesDataService.cs @@ -14,6 +14,7 @@ public interface ICompetencyLearningResourcesDataService IEnumerable GetCompetencyResourceAssessmentQuestionParameters(IEnumerable competencyLearningResourceIds); int AddCompetencyLearningResource(int resourceRefID, string originalResourceName, string description, string resourceType, string link, string catalogue, decimal rating, int competencyID, int adminId); + IEnumerable GetActiveCompetencyLearningResourcesByCompetencyIdAndReferenceId(int competencyId, int referenceId); } public class CompetencyLearningResourcesDataService : ICompetencyLearningResourcesDataService @@ -120,5 +121,20 @@ FROM CompetencyResourceAssessmentQuestionParameters new { competencyLearningResourceIds } ); } + public IEnumerable GetActiveCompetencyLearningResourcesByCompetencyIdAndReferenceId(int competencyId, int referenceId) + { + return connection.Query( + @"SELECT + clr.ID, + clr.CompetencyID, + clr.LearningResourceReferenceID, + clr.AdminID, + lrr.ResourceRefID AS LearningHubResourceReferenceId + FROM CompetencyLearningResources AS clr + INNER JOIN LearningResourceReferences AS lrr ON lrr.ID = clr.LearningResourceReferenceID + WHERE CompetencyID = @competencyId AND ResourceRefID = @referenceId AND clr.RemovedDate IS NULL", + new { competencyId, referenceId } + ); + } } } diff --git a/DigitalLearningSolutions.Web/Controllers/FrameworksController/Signposting.cs b/DigitalLearningSolutions.Web/Controllers/FrameworksController/Signposting.cs index 9acf3bd6c9..d994dee7a9 100644 --- a/DigitalLearningSolutions.Web/Controllers/FrameworksController/Signposting.cs +++ b/DigitalLearningSolutions.Web/Controllers/FrameworksController/Signposting.cs @@ -107,6 +107,13 @@ public IActionResult ConfirmAddCompetencyLearningResourceSummary(CompetencyResou { var frameworkCompetency = frameworkService.GetFrameworkCompetencyById(model.FrameworkCompetencyId.Value); string plainTextDescription = DisplayStringHelper.RemoveMarkup(model.Description); + var competencyLearningResource = competencyLearningResourcesService.GetActiveCompetencyLearningResourcesByCompetencyIdAndReferenceId(frameworkCompetency.CompetencyID, model.ReferenceId); + if (competencyLearningResource.Any()) + { + ModelState.Clear(); + ModelState.AddModelError("LearningResourceExists", "This learning resource is already signposted to the selected competency."); + return View("Developer/AddCompetencyLearningResourceSummary", model); + } int competencyLearningResourceId = competencyLearningResourcesService.AddCompetencyLearningResource(model.ReferenceId, model.ResourceName, plainTextDescription, model.ResourceType, model.Link, model.SelectedCatalogue, model.Rating.Value, frameworkCompetency.CompetencyID, GetAdminId()); return RedirectToAction("StartSignpostingParametersSession", "Frameworks", new { model.FrameworkId, model.FrameworkCompetencyId, model.FrameworkCompetencyGroupId, competencyLearningResourceId }); } diff --git a/DigitalLearningSolutions.Web/Services/CompetencyLearningResourcesService.cs b/DigitalLearningSolutions.Web/Services/CompetencyLearningResourcesService.cs index 3f9a8b295c..525d3e87e0 100644 --- a/DigitalLearningSolutions.Web/Services/CompetencyLearningResourcesService.cs +++ b/DigitalLearningSolutions.Web/Services/CompetencyLearningResourcesService.cs @@ -13,6 +13,7 @@ public interface ICompetencyLearningResourcesService IEnumerable GetCompetencyResourceAssessmentQuestionParameters(IEnumerable competencyLearningResourceIds); int AddCompetencyLearningResource(int resourceRefID, string originalResourceName, string description, string resourceType, string link, string catalogue, decimal rating, int competencyID, int adminId); + IEnumerable GetActiveCompetencyLearningResourcesByCompetencyIdAndReferenceId(int competencyId, int referenceId); } public class CompetencyLearningResourcesService : ICompetencyLearningResourcesService { @@ -40,5 +41,9 @@ public IEnumerable GetCompetencyR { return competencyLearningResourcesDataService.GetCompetencyResourceAssessmentQuestionParameters(competencyLearningResourceIds); } + public IEnumerable GetActiveCompetencyLearningResourcesByCompetencyIdAndReferenceId(int competencyId, int referenceId) + { + return competencyLearningResourcesDataService.GetActiveCompetencyLearningResourcesByCompetencyIdAndReferenceId(competencyId, referenceId); + } } } diff --git a/DigitalLearningSolutions.Web/Views/Frameworks/Developer/AddCompetencyLearningResourceSummary.cshtml b/DigitalLearningSolutions.Web/Views/Frameworks/Developer/AddCompetencyLearningResourceSummary.cshtml index f66b8b24a3..9d4e5cda10 100644 --- a/DigitalLearningSolutions.Web/Views/Frameworks/Developer/AddCompetencyLearningResourceSummary.cshtml +++ b/DigitalLearningSolutions.Web/Views/Frameworks/Developer/AddCompetencyLearningResourceSummary.cshtml @@ -2,72 +2,81 @@ @using DigitalLearningSolutions.Web.Helpers; @model CompetencyResourceSummaryViewModel @{ - ViewData["Title"] = "Add Competency Learning Resource Summary"; - ViewData["Application"] = "Framework Service"; - ViewData["HeaderPathName"] = "Framework Service"; + var errorHasOccurred = !ViewData.ModelState.IsValid; + ViewData["Title"] = errorHasOccurred ? "Error: Add Competency Learning Resource Summary" : "Add Competency Learning Resource Summary"; + ViewData["Application"] = "Framework Service"; + ViewData["HeaderPathName"] = "Framework Service"; } @section NavMenuItems { - + } - @section NavBreadcrumbs { - +@section NavBreadcrumbs { + } -

Add Competency Learning Resource Summary

-
+
+
+ @if (errorHasOccurred) + { + + } +

@ViewData["Title"]

+
+
+
-
-
Competency
-
@Model.NameOfCompetency
-
-
-
Resource name
-
@Model.ResourceName
-
-
-
Resource type
-
@Model.ResourceType
-
-
-
Catalogue
-
@Model.SelectedCatalogue
-
-
-
Description
-
@DisplayStringHelper.RemoveMarkup(Model.Description)
-
-
-
-
- - -
-
-
-
+
+
Competency
+
@Model.NameOfCompetency
+
+
+
Resource name
+
@Model.ResourceName
+
+
+
Resource type
+
@Model.ResourceType
+
+
+
Catalogue
+
@Model.SelectedCatalogue
+
+
+
Description
+
@DisplayStringHelper.RemoveMarkup(Model.Description)
+
+
+
+
+ + +
+
+
+
@Html.HiddenFor(m => m.FrameworkId) @Html.HiddenFor(m => m.FrameworkCompetencyGroupId) @@ -79,19 +88,19 @@ @Html.HiddenFor(m => m.Link) @Html.HiddenFor(m => m.SelectedCatalogue) @Html.HiddenFor(m => m.Rating) -
-