From 353c0ec8be6f00c1fe6380ec54e7f579384fb645 Mon Sep 17 00:00:00 2001 From: swapnamol-abraham Date: Wed, 5 Nov 2025 13:18:03 +0000 Subject: [PATCH] SIT fixes on the ticket TD-5906 & TD-6272 --- .../Controllers/CatalogueController.cs | 57 +++++++++++++------ .../Interfaces/ICatalogueService.cs | 7 +++ .../Services/CatalogueService.cs | 10 ++++ .../Styles/nhsuk/common.scss | 6 +- .../Views/Catalogue/MoodleCategory.cshtml | 15 +++-- .../Views/Catalogue/Index.cshtml | 15 +++-- .../ICatalogueNodeVersionRepository.cs | 8 +++ .../CatalogueNodeVersionRepository.cs | 23 ++++++++ .../Services/ICatalogueService.cs | 8 +++ .../Services/CatalogueService.cs | 13 +++++ .../Services/MoodleApiService.cs | 1 - .../Controllers/CatalogueController.cs | 22 ++++++- .../LearningHub.Nhs.Database.sqlproj | 1 + .../Hierarchy/RemoveCatalogueCategory.sql | 34 +++++++++++ 14 files changed, 189 insertions(+), 31 deletions(-) create mode 100644 WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/RemoveCatalogueCategory.sql diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Controllers/CatalogueController.cs b/AdminUI/LearningHub.Nhs.AdminUI/Controllers/CatalogueController.cs index 316d970c..b649fff2 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/Controllers/CatalogueController.cs +++ b/AdminUI/LearningHub.Nhs.AdminUI/Controllers/CatalogueController.cs @@ -1,35 +1,27 @@ namespace LearningHub.Nhs.AdminUI.Controllers { - using System; - using System.Collections; - using System.Collections.Generic; - using System.ComponentModel.DataAnnotations; - using System.Drawing; - using System.Linq; - using System.Net.Mail; - using System.Text.RegularExpressions; - using System.Threading.Tasks; - using AngleSharp.Io; using LearningHub.Nhs.AdminUI.Configuration; using LearningHub.Nhs.AdminUI.Extensions; using LearningHub.Nhs.AdminUI.Interfaces; using LearningHub.Nhs.AdminUI.Models; using LearningHub.Nhs.Models.Catalogue; using LearningHub.Nhs.Models.Common; - using LearningHub.Nhs.Models.Common.Enums; - using LearningHub.Nhs.Models.Entities.Hierarchy; using LearningHub.Nhs.Models.Moodle; - using LearningHub.Nhs.Models.MyLearning; using LearningHub.Nhs.Models.Paging; using LearningHub.Nhs.Models.Resource; using LearningHub.Nhs.Models.User; - using LearningHub.Nhs.Models.Validation; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; + using System; + using System.Collections.Generic; + using System.Drawing; + using System.Linq; + using System.Text.RegularExpressions; + using System.Threading.Tasks; /// /// Defines the . @@ -731,10 +723,10 @@ public async Task AddUserGroupsToCatalogue(int catalogueNodeId, i [Route("AddCategoryToCatalogue")] public async Task AddCategoryToCatalogue(CatalogueViewModel catalogueViewModel) { - ////if (catalogueViewModel.SelectedCategoryId == 0) - ////{ - //// this.ModelState.AddModelError("SelectedCategoryId", "Please select a category."); - ////} + if (catalogueViewModel.SelectedCategoryId == 0) + { + this.ModelState.AddModelError("SelectedCategoryId", "Please select a category."); + } var vm = await this.catalogueService.GetCatalogueAsync(catalogueViewModel.CatalogueNodeVersionId); vm.SelectedCategoryId = catalogueViewModel.SelectedCategoryId; var vr = await this.catalogueService.AddCategoryToCatalogue(vm); @@ -754,6 +746,35 @@ public async Task AddCategoryToCatalogue(CatalogueViewModel catal } } + /// + /// The RemoveCategoryFromCatalogue. + /// + /// The categoryId/>. + /// The CatalogueNodeVersionId. + /// The . + [HttpGet] + [Route("RemoveCategoryFromCatalogue/{categoryId}/{catalogueNodeVersionId}")] + public async Task RemoveCategoryFromCatalogue(int categoryId, int catalogueNodeVersionId) + { + var vm = await this.catalogueService.GetCatalogueAsync(catalogueNodeVersionId); + vm.SelectedCategoryId = categoryId; + var vr = await this.catalogueService.RemoveCategoryFromCatalogue(vm); + if (vr.Success) + { + var categories = await this.moodleApiService.GetAllMoodleCategoriesAsync(); + vm.MoodleCategories = categories; + vm.SelectedCategoryId = 0; + // Build hierarchical select list + var selectList = BuildList(categories, parentId: null, depth: 0); + vm.MoodleCategorySelectList = new SelectList(selectList, "Value", "Text"); + return this.View("MoodleCategory", vm); + } + else + { + this.ViewBag.ErrorMessage = $"Category update failed."; + return this.View("MoodleCategory", vm); + } + } /// /// The CreateCatalogue. /// diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Interfaces/ICatalogueService.cs b/AdminUI/LearningHub.Nhs.AdminUI/Interfaces/ICatalogueService.cs index 5d58744b..b54694e9 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/Interfaces/ICatalogueService.cs +++ b/AdminUI/LearningHub.Nhs.AdminUI/Interfaces/ICatalogueService.cs @@ -76,5 +76,12 @@ public interface ICatalogueService /// The catalogue. /// Task AddCategoryToCatalogue(CatalogueViewModel catalogue); + + /// + /// RemoveCategoryFromCatalogue + /// + /// The catalogue. + /// + Task RemoveCategoryFromCatalogue(CatalogueViewModel catalogue); } } diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Services/CatalogueService.cs b/AdminUI/LearningHub.Nhs.AdminUI/Services/CatalogueService.cs index b7823242..8db4e0aa 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/Services/CatalogueService.cs +++ b/AdminUI/LearningHub.Nhs.AdminUI/Services/CatalogueService.cs @@ -148,5 +148,15 @@ public async Task AddCategoryToCatalogue(CatalogueViewModel catalog { return await this.facade.PostAsync("Catalogue/AddCategoryToCatalogue", catalogue); } + + /// + /// The RemoveCategoryFromCatalogue. + /// + /// The CatalogueViewModel. + /// The . + public async Task RemoveCategoryFromCatalogue(CatalogueViewModel catalogue) + { + return await this.facade.PostAsync("Catalogue/RemoveCategoryFromCatalogue", catalogue); + } } } diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Styles/nhsuk/common.scss b/AdminUI/LearningHub.Nhs.AdminUI/Styles/nhsuk/common.scss index e4d98671..8f51a7b4 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/Styles/nhsuk/common.scss +++ b/AdminUI/LearningHub.Nhs.AdminUI/Styles/nhsuk/common.scss @@ -8,6 +8,10 @@ .menu-font { font-size: 19px !important; } - +.nhs-item-row { + display: flex; + justify-content: space-between; + align-items: center; +} diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Views/Catalogue/MoodleCategory.cshtml b/AdminUI/LearningHub.Nhs.AdminUI/Views/Catalogue/MoodleCategory.cshtml index be63f99e..bf8e441b 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/Views/Catalogue/MoodleCategory.cshtml +++ b/AdminUI/LearningHub.Nhs.AdminUI/Views/Catalogue/MoodleCategory.cshtml @@ -42,10 +42,14 @@
@if (Model.SelectedCategoryId > 0) { -
- - @selectedCategoryName - Change +
+
+ + @selectedCategoryName + + Change + Remove +
} @@ -88,13 +92,12 @@ @section Scripts {