Skip to content

Commit f9a5817

Browse files
Merge branch 'RC' into Develop/Features/TD-6148-Create-a-PoC-mechanism-which-will-allow-us-to-synchronise-user-tables-between-ELFH-and-User-Profile-DBs
2 parents a3ce679 + af6f0ae commit f9a5817

File tree

14 files changed

+189
-31
lines changed

14 files changed

+189
-31
lines changed

AdminUI/LearningHub.Nhs.AdminUI/Controllers/CatalogueController.cs

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
11
namespace LearningHub.Nhs.AdminUI.Controllers
22
{
3-
using System;
4-
using System.Collections;
5-
using System.Collections.Generic;
6-
using System.ComponentModel.DataAnnotations;
7-
using System.Drawing;
8-
using System.Linq;
9-
using System.Net.Mail;
10-
using System.Text.RegularExpressions;
11-
using System.Threading.Tasks;
12-
using AngleSharp.Io;
133
using LearningHub.Nhs.AdminUI.Configuration;
144
using LearningHub.Nhs.AdminUI.Extensions;
155
using LearningHub.Nhs.AdminUI.Interfaces;
166
using LearningHub.Nhs.AdminUI.Models;
177
using LearningHub.Nhs.Models.Catalogue;
188
using LearningHub.Nhs.Models.Common;
19-
using LearningHub.Nhs.Models.Common.Enums;
20-
using LearningHub.Nhs.Models.Entities.Hierarchy;
219
using LearningHub.Nhs.Models.Moodle;
22-
using LearningHub.Nhs.Models.MyLearning;
2310
using LearningHub.Nhs.Models.Paging;
2411
using LearningHub.Nhs.Models.Resource;
2512
using LearningHub.Nhs.Models.User;
26-
using LearningHub.Nhs.Models.Validation;
2713
using Microsoft.AspNetCore.Hosting;
2814
using Microsoft.AspNetCore.Http;
2915
using Microsoft.AspNetCore.Mvc;
3016
using Microsoft.AspNetCore.Mvc.Rendering;
3117
using Microsoft.Extensions.Logging;
3218
using Microsoft.Extensions.Options;
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Drawing;
22+
using System.Linq;
23+
using System.Text.RegularExpressions;
24+
using System.Threading.Tasks;
3325

3426
/// <summary>
3527
/// Defines the <see cref="CatalogueController" />.
@@ -731,10 +723,10 @@ public async Task<IActionResult> AddUserGroupsToCatalogue(int catalogueNodeId, i
731723
[Route("AddCategoryToCatalogue")]
732724
public async Task<IActionResult> AddCategoryToCatalogue(CatalogueViewModel catalogueViewModel)
733725
{
734-
////if (catalogueViewModel.SelectedCategoryId == 0)
735-
////{
736-
//// this.ModelState.AddModelError("SelectedCategoryId", "Please select a category.");
737-
////}
726+
if (catalogueViewModel.SelectedCategoryId == 0)
727+
{
728+
this.ModelState.AddModelError("SelectedCategoryId", "Please select a category.");
729+
}
738730
var vm = await this.catalogueService.GetCatalogueAsync(catalogueViewModel.CatalogueNodeVersionId);
739731
vm.SelectedCategoryId = catalogueViewModel.SelectedCategoryId;
740732
var vr = await this.catalogueService.AddCategoryToCatalogue(vm);
@@ -754,6 +746,35 @@ public async Task<IActionResult> AddCategoryToCatalogue(CatalogueViewModel catal
754746
}
755747
}
756748

749+
/// <summary>
750+
/// The RemoveCategoryFromCatalogue.
751+
/// </summary>
752+
/// <param name="categoryId">The categoryId/>.</param>
753+
/// <param name="catalogueNodeVersionId">The CatalogueNodeVersionId.</param>
754+
/// <returns>The <see cref="Task{IActionResult}"/>.</returns>
755+
[HttpGet]
756+
[Route("RemoveCategoryFromCatalogue/{categoryId}/{catalogueNodeVersionId}")]
757+
public async Task<IActionResult> RemoveCategoryFromCatalogue(int categoryId, int catalogueNodeVersionId)
758+
{
759+
var vm = await this.catalogueService.GetCatalogueAsync(catalogueNodeVersionId);
760+
vm.SelectedCategoryId = categoryId;
761+
var vr = await this.catalogueService.RemoveCategoryFromCatalogue(vm);
762+
if (vr.Success)
763+
{
764+
var categories = await this.moodleApiService.GetAllMoodleCategoriesAsync();
765+
vm.MoodleCategories = categories;
766+
vm.SelectedCategoryId = 0;
767+
// Build hierarchical select list
768+
var selectList = BuildList(categories, parentId: null, depth: 0);
769+
vm.MoodleCategorySelectList = new SelectList(selectList, "Value", "Text");
770+
return this.View("MoodleCategory", vm);
771+
}
772+
else
773+
{
774+
this.ViewBag.ErrorMessage = $"Category update failed.";
775+
return this.View("MoodleCategory", vm);
776+
}
777+
}
757778
/// <summary>
758779
/// The CreateCatalogue.
759780
/// </summary>

AdminUI/LearningHub.Nhs.AdminUI/Interfaces/ICatalogueService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,12 @@ public interface ICatalogueService
7676
/// <param name="catalogue">The catalogue.</param>
7777
/// <returns></returns>
7878
Task<ApiResponse> AddCategoryToCatalogue(CatalogueViewModel catalogue);
79+
80+
/// <summary>
81+
/// RemoveCategoryFromCatalogue
82+
/// </summary>
83+
/// <param name="catalogue">The catalogue.</param>
84+
/// <returns></returns>
85+
Task<ApiResponse> RemoveCategoryFromCatalogue(CatalogueViewModel catalogue);
7986
}
8087
}

AdminUI/LearningHub.Nhs.AdminUI/Services/CatalogueService.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,15 @@ public async Task<ApiResponse> AddCategoryToCatalogue(CatalogueViewModel catalog
148148
{
149149
return await this.facade.PostAsync<ApiResponse, CatalogueViewModel>("Catalogue/AddCategoryToCatalogue", catalogue);
150150
}
151+
152+
/// <summary>
153+
/// The RemoveCategoryFromCatalogue.
154+
/// </summary>
155+
/// <param name="catalogue">The CatalogueViewModel.</param>
156+
/// <returns>The <see cref="Task{IActionResult}"/>.</returns>
157+
public async Task<ApiResponse> RemoveCategoryFromCatalogue(CatalogueViewModel catalogue)
158+
{
159+
return await this.facade.PostAsync<ApiResponse, CatalogueViewModel>("Catalogue/RemoveCategoryFromCatalogue", catalogue);
160+
}
151161
}
152162
}

AdminUI/LearningHub.Nhs.AdminUI/Styles/nhsuk/common.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
.menu-font {
99
font-size: 19px !important;
1010
}
11-
11+
.nhs-item-row {
12+
display: flex;
13+
justify-content: space-between;
14+
align-items: center;
15+
}
1216

1317

AdminUI/LearningHub.Nhs.AdminUI/Views/Catalogue/MoodleCategory.cshtml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@
4242
<div class="form-group">
4343
@if (Model.SelectedCategoryId > 0)
4444
{
45-
<div id="selectedCategoryDisplay" class="nhsuk-u-padding-left-3">
46-
<label>Selected Category:</label>
47-
<span class="selected-category nhsuk-u-padding-right-8">@selectedCategoryName</span>
48-
<a href="#" onclick="return DisplayCategory();">Change</a>
45+
<div class="nhs-item-row">
46+
<div id="selectedCategoryDisplay" class="nhsuk-u-padding-left-3">
47+
<label>Selected Category:</label>
48+
<span class="selected-category nhsuk-u-padding-right-8">@selectedCategoryName</span>
49+
50+
<a href="#" onclick="return DisplayCategory();">Change</a>
51+
<a asp-controller="Catalogue" asp-action="RemoveCategoryFromCatalogue" asp-route-categoryId="@Model.SelectedCategoryId" asp-route-catalogueNodeVersionId="@Model.CatalogueNodeVersionId" class="nhsuk-u-padding-left-3">Remove</a>
52+
</div>
4953
</div>
5054
}
5155

@@ -88,13 +92,12 @@
8892
@section Scripts {
8993
<script>
9094
function DisplayCategory() {
91-
debugger
9295
// Show the category selection div
9396
document.getElementById('divcategory').style.display = 'block';
9497
document.getElementById('example-error').style.display = 'none'
9598
document.getElementById('errortext').style.display = 'none'
9699
document.getElementById('diverror').classList.remove('nhsuk-form-group--error');
97-
100+
98101
// Hide the selected category display div
99102
var selectedCategoryDiv = document.getElementById('selectedCategoryDisplay');
100103
if (selectedCategoryDiv) {

LearningHub.Nhs.WebUI/Views/Catalogue/Index.cshtml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@
166166
@Html.Raw(Model.NodeDetails.Description)
167167
</div>
168168
}
169+
170+
@if (Model.MoodleCategories != null)
171+
{
172+
<div class="folder-description">
173+
@Html.Raw(Model.MoodleCategories.Last().Description)
174+
</div>
175+
}
169176
</div>
170177

171178
@* Tab header *@
@@ -180,10 +187,10 @@
180187
</label>
181188
</div>
182189
<div class="navbar-collapse collapse" id="catalogue-details">
183-
<ul class="navbar-nav">
184-
<li class="subnavwhite-item @(ViewBag.ActiveTab == "browse" ? "active" : string.Empty)">
185-
<a tabindex="0" class="subnavwhite-link text-nowrap" asp-controller="Catalogue" asp-route-reference="@Model.Catalogue.Url" asp-route-tab="browse" asp-fragment="catalogue-details">Resources</a>
186-
</li>
190+
<ul class="navbar-nav">
191+
<li class="subnavwhite-item @(ViewBag.ActiveTab == "browse" ? "active" : string.Empty)">
192+
<a tabindex="0" class="subnavwhite-link text-nowrap" asp-controller="Catalogue" asp-route-reference="@Model.Catalogue.Url" asp-route-tab="browse" asp-fragment="catalogue-details">Resources</a>
193+
</li>
187194
@if (Model.Catalogue.SelectedCategoryId > 0)
188195
{
189196
<li class="subnavwhite-item @(ViewBag.ActiveTab == "courses" ? "active" : string.Empty)">

OpenAPI/LearningHub.Nhs.OpenApi.Repositories.Interface/Repositories/Hierarchy/ICatalogueNodeVersionRepository.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ public interface ICatalogueNodeVersionRepository : IGenericRepository<CatalogueN
6363
/// <returns></returns>
6464
Task AddCategoryToCatalogueAsync(int userId, CatalogueViewModel vm);
6565

66+
/// <summary>
67+
/// The RemoveCategoryFromCatalogueAsync.
68+
/// </summary>
69+
/// <param name="userId">The userId.</param>
70+
/// <param name="vm">The viewmodel.</param>
71+
/// <returns></returns>
72+
Task RemoveCategoryFromCatalogueAsync(int userId, CatalogueViewModel vm);
73+
6674
/// <summary>
6775
/// The CreateCatalogueAsync.
6876
/// </summary>

OpenAPI/LearningHub.Nhs.OpenApi.Repositories/Repositories/Hierarchy/CatalogueNodeVersionRepository.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,29 @@ public async Task AddCategoryToCatalogueAsync(int userId, CatalogueViewModel vm)
239239
}
240240
}
241241

242+
/// <summary>
243+
/// The RemoveCategoryFromCatalogueAsync.
244+
/// </summary>
245+
/// <param name="userId">The userId.</param>
246+
/// <param name="vm">The viewmodel.</param>
247+
/// <returns></returns>
248+
public async Task RemoveCategoryFromCatalogueAsync(int userId, CatalogueViewModel vm)
249+
{
250+
try
251+
{
252+
var param0 = new SqlParameter("@p0", SqlDbType.Int) { Value = userId };
253+
var param1 = new SqlParameter("@p1", SqlDbType.Int) { Value = vm.CatalogueNodeVersionId };
254+
var param2 = new SqlParameter("@p2", SqlDbType.Int) { Value = vm.SelectedCategoryId };
255+
var param3 = new SqlParameter("@p3", SqlDbType.Int) { Value = TimezoneOffsetManager.UserTimezoneOffset ?? (object)DBNull.Value };
256+
257+
await DbContext.Database.ExecuteSqlRawAsync("hierarchy.RemoveCatalogueCategory @p0, @p1, @p2, @p3", param0, param1, param2, param3);
258+
}
259+
catch (Exception ex)
260+
{
261+
throw new Exception(ex.Message);
262+
}
263+
}
264+
242265
/// <summary>
243266
/// Get Catlogue by reference.
244267
/// </summary>

OpenAPI/LearningHub.Nhs.OpenApi.Services.Interface/Services/ICatalogueService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ public interface ICatalogueService
157157
/// <returns></returns>
158158
Task<LearningHubValidationResult> AddCategoryToCatalogueAsync(int userId, CatalogueViewModel catalogue);
159159

160+
/// <summary>
161+
/// The RemoveCategoryFromCatalogueAsync.
162+
/// </summary>
163+
/// <param name="userId">The userId.</param>
164+
/// <param name="catalogue">The catalogue.</param>
165+
/// <returns>The catalogue id.</returns>
166+
Task<LearningHubValidationResult> RemoveCategoryFromCatalogueAsync(int userId, CatalogueViewModel catalogue);
167+
160168
/// <summary>
161169
/// The UpdateCatalogueAsync.
162170
/// </summary>

OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/CatalogueService.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,19 @@ public async Task<LearningHubValidationResult> AddCategoryToCatalogueAsync(int u
608608
return new LearningHubValidationResult(true);
609609
}
610610

611+
/// <summary>
612+
/// The RemoveCategoryFromCatalogueAsync.
613+
/// </summary>
614+
/// <param name="userId">The userId.</param>
615+
/// <param name="catalogue">The catalogue.</param>
616+
/// <returns>The catalogue id.</returns>
617+
public async Task<LearningHubValidationResult> RemoveCategoryFromCatalogueAsync(int userId, CatalogueViewModel catalogue)
618+
{
619+
await this.catalogueNodeVersionRepository.RemoveCategoryFromCatalogueAsync(userId, catalogue);
620+
621+
return new LearningHubValidationResult(true);
622+
}
623+
611624
/// <summary>
612625
/// The IsUserLocalAdminAsync.
613626
/// </summary>

0 commit comments

Comments
 (0)