From d3f77100b90c186f9b2c711b7a74ff264f588169 Mon Sep 17 00:00:00 2001 From: swapnamol-abraham Date: Thu, 16 Apr 2026 10:30:40 +0100 Subject: [PATCH] TD-7125: LH Admin UI - when category is not assigned to the catalogue and clicked save results in error --- .../Controllers/CatalogueController.cs | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Controllers/CatalogueController.cs b/AdminUI/LearningHub.Nhs.AdminUI/Controllers/CatalogueController.cs index 25aa6cd4..b9f1b5e0 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/Controllers/CatalogueController.cs +++ b/AdminUI/LearningHub.Nhs.AdminUI/Controllers/CatalogueController.cs @@ -738,20 +738,29 @@ public async Task AddCategoryToCatalogue(CatalogueViewModel catal if (string.IsNullOrEmpty(catalogueViewModel.SelectedCategoryId)) { 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); - if (vr.Success) - { + var vm = await this.catalogueService.GetCatalogueAsync(catalogueViewModel.CatalogueNodeVersionId); var categories = await this.moodleBridgeApiService.GetAllMoodleCategoriesAsync(); vm.MoodleCategorySelectList = BuildMoodleCategorySelectList(categories); + return this.View("MoodleCategory", vm); } + else { - this.ViewBag.ErrorMessage = $"Category Update failed."; - return this.View("MoodleCategory", vm); + var vm = await this.catalogueService.GetCatalogueAsync(catalogueViewModel.CatalogueNodeVersionId); + vm.SelectedCategoryId = catalogueViewModel.SelectedCategoryId; + var vr = await this.catalogueService.AddCategoryToCatalogue(vm); + if (vr.Success) + { + var categories = await this.moodleBridgeApiService.GetAllMoodleCategoriesAsync(); + vm.MoodleCategorySelectList = BuildMoodleCategorySelectList(categories); + return this.View("MoodleCategory", vm); + } + else + { + this.ViewBag.ErrorMessage = $"Category Update failed."; + return this.View("MoodleCategory", vm); + } } }