diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Controllers/ResourceController.cs b/AdminUI/LearningHub.Nhs.AdminUI/Controllers/ResourceController.cs index 2338e457c..1a662d524 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/Controllers/ResourceController.cs +++ b/AdminUI/LearningHub.Nhs.AdminUI/Controllers/ResourceController.cs @@ -91,11 +91,15 @@ public ResourceController( /// The Details. /// /// The id. + /// The activeTab. + /// The status. /// The . [HttpGet] - public async Task Details(int id) + public async Task Details(int id, string activeTab = "details", string status = "") { var resource = await this.resourceService.GetResourceVersionExtendedViewModelAsync(id); + this.ViewBag.ActiveTab = activeTab; + this.ViewBag.Status = status; return this.View(resource); } @@ -138,6 +142,41 @@ public async Task GetValidationResults(int resourceVersionId) return this.PartialView("_ValidationResults", vm); } + /// + /// The GetDevIdDetails. + /// + /// The resourceVersionId. + /// The . + [HttpPost] + public async Task GetDevIdDetails(int resourceVersionId) + { + var vm = await this.resourceService.GetResourceVersionDevIdDetailsAsync(resourceVersionId); + + return this.PartialView("_DevIdDetails", vm); + } + + /// + /// The update the dev Id details. + /// + /// The model. + /// The . + [HttpPost] + public async Task UpdateDevIdDetails(ResourceVersionDevIdViewModel model) + { + var message = string.Empty; + if (await this.resourceService.DoesDevIdExistsAsync(model.DevId)) + { + message = "Duplicate"; + } + else + { + await this.resourceService.UpdateDevIdDetailsAsync(model); + message = "Success"; + } + + return this.RedirectToAction("Details", new { id = model.ResourceVersionId, activeTab = "devId", status = message }); + } + /// /// The Index. /// diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Interfaces/IResourceService.cs b/AdminUI/LearningHub.Nhs.AdminUI/Interfaces/IResourceService.cs index 826c98b55..703be694e 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/Interfaces/IResourceService.cs +++ b/AdminUI/LearningHub.Nhs.AdminUI/Interfaces/IResourceService.cs @@ -32,9 +32,30 @@ public interface IResourceService /// The GetResourceVersionValidationResultAsync. /// /// The resourceVersionId. - /// The . + /// The . Task GetResourceVersionValidationResultAsync(int resourceVersionId); + /// + /// The GetResourceVersionDevIdDetailsAsync. + /// + /// The resourceVersionId. + /// The . + Task GetResourceVersionDevIdDetailsAsync(int resourceVersionId); + + /// + /// Check dev id already exist against a resource. + /// + /// string devId. + /// The . + Task DoesDevIdExistsAsync(string devId); + + /// + /// To update dev id details for a resource. + /// + /// the ResourceVersionDevIdViewModel. + /// The . + Task UpdateDevIdDetailsAsync(ResourceVersionDevIdViewModel model); + /// /// The GetResourceVersionExtendedViewModelAsync. /// diff --git a/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj b/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj index 4ea6a2e6a..798171c31 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj +++ b/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj @@ -89,7 +89,7 @@ - + diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Services/ResourceService.cs b/AdminUI/LearningHub.Nhs.AdminUI/Services/ResourceService.cs index d0d595b52..4c6e3fe46 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/Services/ResourceService.cs +++ b/AdminUI/LearningHub.Nhs.AdminUI/Services/ResourceService.cs @@ -2,6 +2,7 @@ { using System; using System.Collections.Generic; + using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; @@ -130,6 +131,89 @@ public async Task GetResourceVersionVa return viewmodel; } + /// + /// The GetResourceVersionDevIdDetailsAsync. + /// + /// The resourceVersionId. + /// The . + public async Task GetResourceVersionDevIdDetailsAsync(int resourceVersionId) + { + ResourceVersionDevIdViewModel viewmodel = null; + + var client = await this.LearningHubHttpClient.GetClientAsync(); + + var request = $"Resource/GetResourceVersionDevIdDetails/{resourceVersionId.ToString()}"; + var response = await client.GetAsync(request).ConfigureAwait(false); + + if (response.IsSuccessStatusCode) + { + var result = response.Content.ReadAsStringAsync().Result; + viewmodel = JsonConvert.DeserializeObject(result); + } + else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized + || + response.StatusCode == System.Net.HttpStatusCode.Forbidden) + { + throw new Exception("AccessDenied"); + } + + return viewmodel; + } + + /// + /// The GetResourceVersionDevIdDetailsAsync. + /// + /// The devId. + /// The . + public async Task DoesDevIdExistsAsync(string devId) + { + var client = await this.LearningHubHttpClient.GetClientAsync(); + + var request = $"Resource/DoesDevIdExists/{devId}"; + var response = await client.GetAsync(request).ConfigureAwait(false); + var doesDevIdExist = false; + if (response.IsSuccessStatusCode) + { + var result = response.Content.ReadAsStringAsync().Result; + doesDevIdExist = JsonConvert.DeserializeObject(result); + } + else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized + || + response.StatusCode == System.Net.HttpStatusCode.Forbidden) + { + throw new Exception("AccessDenied"); + } + + return doesDevIdExist; + } + + /// + /// Update dev id details for a resource. + /// + /// The model. + /// The . + /// the exception. + public async Task UpdateDevIdDetailsAsync(ResourceVersionDevIdViewModel model) + { + var json = JsonConvert.SerializeObject(model); + var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); + + var client = await this.LearningHubHttpClient.GetClientAsync(); + + var request = $"Resource/UpdateDevId"; + var response = await client.PutAsync(request, stringContent).ConfigureAwait(false); + + if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.Forbidden) + { + throw new Exception("AccessDenied"); + } + + if (!response.IsSuccessStatusCode) + { + throw new Exception("Update first name failed!"); + } + } + /// /// The GetResourceVersionExtendedViewModelAsync. /// diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Views/Resource/Details.cshtml b/AdminUI/LearningHub.Nhs.AdminUI/Views/Resource/Details.cshtml index a2df6a2c6..44b2f9b11 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/Views/Resource/Details.cshtml +++ b/AdminUI/LearningHub.Nhs.AdminUI/Views/Resource/Details.cshtml @@ -5,862 +5,913 @@ @inject IOptions webSettings @{ - ViewData["Title"] = "Details"; + ViewData["Title"] = "Details"; + var activetab = this.ViewBag.ActiveTab; } @section Styles{ - + }
- -
-
+ +
+
+
+ + @if (Model.ResourceVersionId == 0) + { +
Resource Version not found
+ } + else + { +
+
@Model.Title (@Model.VersionStatusDescription)
+
+ @if (Model.VersionStatusEnum == VersionStatusEnum.Published) + { + + } + @if (Model.VersionStatusEnum == VersionStatusEnum.Publishing || Model.VersionStatusEnum == VersionStatusEnum.FailedToPublish) + { + + } + +
- - @if (Model.ResourceVersionId == 0) - { -
Resource Version not found
- } - else - { -
-
@Model.Title (@Model.VersionStatusDescription)
-
- @if (Model.VersionStatusEnum == VersionStatusEnum.Published) - { - - } - @if (Model.VersionStatusEnum == VersionStatusEnum.Publishing || Model.VersionStatusEnum == VersionStatusEnum.FailedToPublish) - { - - } - -
-
-