Skip to content

Commit d2d66eb

Browse files
authored
Merge pull request #664 from TechnologyEnhancedLearning/Develop/Feature/TD-2396-Add-ability-to-insert-Development-ID
TD-2396: Add ability to insert Dev ID
2 parents c9f722f + 9d6b807 commit d2d66eb

File tree

33 files changed

+1218
-834
lines changed

33 files changed

+1218
-834
lines changed

AdminUI/LearningHub.Nhs.AdminUI/Controllers/ResourceController.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,15 @@ public ResourceController(
9191
/// The Details.
9292
/// </summary>
9393
/// <param name="id">The id<see cref="int"/>.</param>
94+
/// <param name="activeTab">The activeTab<see cref="string"/>.</param>
95+
/// <param name="status">The status<see cref="string"/>.</param>
9496
/// <returns>The <see cref="Task{IActionResult}"/>.</returns>
9597
[HttpGet]
96-
public async Task<IActionResult> Details(int id)
98+
public async Task<IActionResult> Details(int id, string activeTab = "details", string status = "")
9799
{
98100
var resource = await this.resourceService.GetResourceVersionExtendedViewModelAsync(id);
101+
this.ViewBag.ActiveTab = activeTab;
102+
this.ViewBag.Status = status;
99103
return this.View(resource);
100104
}
101105

@@ -138,6 +142,41 @@ public async Task<IActionResult> GetValidationResults(int resourceVersionId)
138142
return this.PartialView("_ValidationResults", vm);
139143
}
140144

145+
/// <summary>
146+
/// The GetDevIdDetails.
147+
/// </summary>
148+
/// <param name="resourceVersionId">The resourceVersionId<see cref="int"/>.</param>
149+
/// <returns>The <see cref="Task{IActionResult}"/>.</returns>
150+
[HttpPost]
151+
public async Task<IActionResult> GetDevIdDetails(int resourceVersionId)
152+
{
153+
var vm = await this.resourceService.GetResourceVersionDevIdDetailsAsync(resourceVersionId);
154+
155+
return this.PartialView("_DevIdDetails", vm);
156+
}
157+
158+
/// <summary>
159+
/// The update the dev Id details.
160+
/// </summary>
161+
/// <param name="model">The model.</param>
162+
/// <returns>The <see cref="Task{IActionResult}"/>.</returns>
163+
[HttpPost]
164+
public async Task<IActionResult> UpdateDevIdDetails(ResourceVersionDevIdViewModel model)
165+
{
166+
var message = string.Empty;
167+
if (await this.resourceService.DoesDevIdExistsAsync(model.DevId))
168+
{
169+
message = "Duplicate";
170+
}
171+
else
172+
{
173+
await this.resourceService.UpdateDevIdDetailsAsync(model);
174+
message = "Success";
175+
}
176+
177+
return this.RedirectToAction("Details", new { id = model.ResourceVersionId, activeTab = "devId", status = message });
178+
}
179+
141180
/// <summary>
142181
/// The Index.
143182
/// </summary>

AdminUI/LearningHub.Nhs.AdminUI/Interfaces/IResourceService.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,30 @@ public interface IResourceService
3232
/// The GetResourceVersionValidationResultAsync.
3333
/// </summary>
3434
/// <param name="resourceVersionId">The resourceVersionId<see cref="int"/>.</param>
35-
/// <returns>The <see cref="Task{ResourceVersionEventViewModel}}"/>.</returns>
35+
/// <returns>The <see cref="Task{ResourceVersionValidationResultViewModel}}"/>.</returns>
3636
Task<ResourceVersionValidationResultViewModel> GetResourceVersionValidationResultAsync(int resourceVersionId);
3737

38+
/// <summary>
39+
/// The GetResourceVersionDevIdDetailsAsync.
40+
/// </summary>
41+
/// <param name="resourceVersionId">The resourceVersionId<see cref="int"/>.</param>
42+
/// <returns>The <see cref="Task{ResourceVersionDevIdViewModel}}"/>.</returns>
43+
Task<ResourceVersionDevIdViewModel> GetResourceVersionDevIdDetailsAsync(int resourceVersionId);
44+
45+
/// <summary>
46+
/// Check dev id already exist against a resource.
47+
/// </summary>
48+
/// <param name="devId">string devId.</param>
49+
/// <returns>The <see cref="Task{bool}"/>.</returns>
50+
Task<bool> DoesDevIdExistsAsync(string devId);
51+
52+
/// <summary>
53+
/// To update dev id details for a resource.
54+
/// </summary>
55+
/// <param name="model">the ResourceVersionDevIdViewModel.</param>
56+
/// <returns>The <see cref="Task{ResourceVersionDevIdViewModel}}"/>.</returns>
57+
Task UpdateDevIdDetailsAsync(ResourceVersionDevIdViewModel model);
58+
3859
/// <summary>
3960
/// The GetResourceVersionExtendedViewModelAsync.
4061
/// </summary>

AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<PackageReference Include="HtmlSanitizer" Version="6.0.453" />
9090
<PackageReference Include="IdentityModel" Version="4.4.0" />
9191
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.2" />
92-
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.40" />
92+
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.41" />
9393
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
9494
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0" />
9595
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.0" />

AdminUI/LearningHub.Nhs.AdminUI/Services/ResourceService.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.Collections.Generic;
5+
using System.Net;
56
using System.Net.Http;
67
using System.Text;
78
using System.Threading.Tasks;
@@ -130,6 +131,89 @@ public async Task<ResourceVersionValidationResultViewModel> GetResourceVersionVa
130131
return viewmodel;
131132
}
132133

134+
/// <summary>
135+
/// The GetResourceVersionDevIdDetailsAsync.
136+
/// </summary>
137+
/// <param name="resourceVersionId">The resourceVersionId<see cref="int"/>.</param>
138+
/// <returns>The <see cref="List{ResourceVersionDevIdViewModel}"/>.</returns>
139+
public async Task<ResourceVersionDevIdViewModel> GetResourceVersionDevIdDetailsAsync(int resourceVersionId)
140+
{
141+
ResourceVersionDevIdViewModel viewmodel = null;
142+
143+
var client = await this.LearningHubHttpClient.GetClientAsync();
144+
145+
var request = $"Resource/GetResourceVersionDevIdDetails/{resourceVersionId.ToString()}";
146+
var response = await client.GetAsync(request).ConfigureAwait(false);
147+
148+
if (response.IsSuccessStatusCode)
149+
{
150+
var result = response.Content.ReadAsStringAsync().Result;
151+
viewmodel = JsonConvert.DeserializeObject<ResourceVersionDevIdViewModel>(result);
152+
}
153+
else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized
154+
||
155+
response.StatusCode == System.Net.HttpStatusCode.Forbidden)
156+
{
157+
throw new Exception("AccessDenied");
158+
}
159+
160+
return viewmodel;
161+
}
162+
163+
/// <summary>
164+
/// The GetResourceVersionDevIdDetailsAsync.
165+
/// </summary>
166+
/// <param name="devId">The devId<see cref="string"/>.</param>
167+
/// <returns>The <see cref="List{ResourceVersionDevIdViewModel}"/>.</returns>
168+
public async Task<bool> DoesDevIdExistsAsync(string devId)
169+
{
170+
var client = await this.LearningHubHttpClient.GetClientAsync();
171+
172+
var request = $"Resource/DoesDevIdExists/{devId}";
173+
var response = await client.GetAsync(request).ConfigureAwait(false);
174+
var doesDevIdExist = false;
175+
if (response.IsSuccessStatusCode)
176+
{
177+
var result = response.Content.ReadAsStringAsync().Result;
178+
doesDevIdExist = JsonConvert.DeserializeObject<bool>(result);
179+
}
180+
else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized
181+
||
182+
response.StatusCode == System.Net.HttpStatusCode.Forbidden)
183+
{
184+
throw new Exception("AccessDenied");
185+
}
186+
187+
return doesDevIdExist;
188+
}
189+
190+
/// <summary>
191+
/// Update dev id details for a resource.
192+
/// </summary>
193+
/// <param name="model">The model.</param>
194+
/// <returns>The <see cref="List{ResourceVersionDevIdViewModel}"/>.</returns>
195+
/// <exception cref="Exception">the exception.</exception>
196+
public async Task UpdateDevIdDetailsAsync(ResourceVersionDevIdViewModel model)
197+
{
198+
var json = JsonConvert.SerializeObject(model);
199+
var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
200+
201+
var client = await this.LearningHubHttpClient.GetClientAsync();
202+
203+
var request = $"Resource/UpdateDevId";
204+
var response = await client.PutAsync(request, stringContent).ConfigureAwait(false);
205+
206+
if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.Forbidden)
207+
{
208+
throw new Exception("AccessDenied");
209+
}
210+
211+
if (!response.IsSuccessStatusCode)
212+
{
213+
throw new Exception("Update first name failed!");
214+
}
215+
}
216+
133217
/// <summary>
134218
/// The GetResourceVersionExtendedViewModelAsync.
135219
/// </summary>

0 commit comments

Comments
 (0)