Skip to content

Commit 25bffe8

Browse files
authored
Merge pull request #2718 from TechnologyEnhancedLearning/Develop/feature/TD-3915-DelegatesController-refactor
TD-3915-DelegatesController - refactor
2 parents 855cca2 + 1f3e655 commit 25bffe8

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

DigitalLearningSolutions.Web/Controllers/SuperAdmin/Delegates/DelegatesController.cs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

22
namespace DigitalLearningSolutions.Web.Controllers.SuperAdmin.Delegates
33
{
4-
using DigitalLearningSolutions.Data.DataServices;
5-
using DigitalLearningSolutions.Data.DataServices.UserDataService;
64
using DigitalLearningSolutions.Data.Enums;
75
using DigitalLearningSolutions.Data.Helpers;
86
using DigitalLearningSolutions.Data.Models.SearchSortFilterPaginate;
@@ -27,18 +25,16 @@ namespace DigitalLearningSolutions.Web.Controllers.SuperAdmin.Delegates
2725
[SetSelectedTab(nameof(NavMenuTab.Admins))]
2826
public class DelegatesController : Controller
2927
{
30-
private readonly IUserDataService userDataService;
3128
private readonly ISearchSortFilterPaginateService searchSortFilterPaginateService;
32-
private readonly ICentresDataService centresDataService;
29+
private readonly ICentresService centresService;
3330
private readonly IUserService userService;
34-
public DelegatesController(IUserDataService userDataService,
35-
ICentresDataService centresDataService,
31+
public DelegatesController(
32+
ICentresService centresService,
3633
ISearchSortFilterPaginateService searchSortFilterPaginateService,
3734
IUserService userService
3835
)
3936
{
40-
this.userDataService = userDataService;
41-
this.centresDataService = centresDataService;
37+
this.centresService = centresService;
4238
this.searchSortFilterPaginateService = searchSortFilterPaginateService;
4339
this.userService = userService;
4440
}
@@ -107,9 +103,9 @@ public IActionResult Index(
107103
}
108104
}
109105
}
110-
(var Delegates, var ResultCount) = this.userDataService.GetAllDelegates(Search ?? string.Empty, offSet, itemsPerPage ?? 0, DelegateId, AccountStatus, LHLinkStatus, CentreId, AuthHelper.FailedLoginThreshold);
106+
(var Delegates, var ResultCount) = this.userService.GetAllDelegates(Search ?? string.Empty, offSet, itemsPerPage ?? 0, DelegateId, AccountStatus, LHLinkStatus, CentreId, AuthHelper.FailedLoginThreshold);
111107

112-
var centres = centresDataService.GetAllCentres().ToList();
108+
var centres = centresService.GetAllCentres().ToList();
113109
centres.Insert(0, (0, "Any"));
114110

115111
var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions(
@@ -183,7 +179,7 @@ public List<string> GetLHLinkStatus()
183179
[Route("SuperAdmin/Delegates/{delegateId=0:int}/InactivateDelegateConfirmation")]
184180
public IActionResult InactivateDelegateConfirmation(int delegateId = 0)
185181
{
186-
var delegateEntity = userDataService.GetDelegateById(delegateId);
182+
var delegateEntity = userService.GetDelegateById(delegateId);
187183
if (!delegateEntity.DelegateAccount.Active)
188184
{
189185
return StatusCode((int)HttpStatusCode.Gone);
@@ -219,7 +215,7 @@ public IActionResult InactivateDelegateConfirmation(ConfirmationViewModel confir
219215
TempData["DelegateId"] = delegateId;
220216
if (confirmationViewModel.IsChecked)
221217
{
222-
this.userDataService.DeactivateDelegateUser(delegateId);
218+
this.userService.DeactivateDelegateUser(delegateId);
223219
return RedirectToAction("Index", "Delegates", new { DelegateId = delegateId });
224220
}
225221
else
@@ -234,7 +230,7 @@ public IActionResult InactivateDelegateConfirmation(ConfirmationViewModel confir
234230
[Route("SuperAdmin/Delegates/{delegateId=0:int}/ActivateDelegate")]
235231
public IActionResult ActivateDelegate(int delegateId = 0)
236232
{
237-
userDataService.ActivateDelegateUser(delegateId);
233+
userService.ActivateDelegateUser(delegateId);
238234
TempData["DelegateId"] = delegateId;
239235
return RedirectToAction("Index", "Delegates", new { DelegateId = delegateId });
240236
}
@@ -243,11 +239,11 @@ public IActionResult ActivateDelegate(int delegateId = 0)
243239
[Route("SuperAdmin/Delegates/{delegateId=0:int}/RemoveCentreEmailConfirmation")]
244240
public IActionResult RemoveCentreEmailConfirmation(int delegateId = 0)
245241
{
246-
var delegateEntity = userDataService.GetDelegateById(delegateId);
242+
var delegateEntity = userService.GetDelegateById(delegateId);
247243

248244
if (delegateEntity != null)
249245
{
250-
var userCenterEmail = userDataService.GetCentreEmail(delegateEntity.DelegateAccount.UserId, delegateEntity.DelegateAccount.CentreId);
246+
var userCenterEmail = userService.GetCentreEmail(delegateEntity.DelegateAccount.UserId, delegateEntity.DelegateAccount.CentreId);
251247
if (userCenterEmail == null)
252248
return StatusCode((int)HttpStatusCode.Gone);
253249
}
@@ -282,10 +278,10 @@ public IActionResult RemoveCentreEmailConfirmation(ConfirmationViewModel confirm
282278
TempData["DelegateId"] = delegateId;
283279
if (confirmationViewModel.IsChecked)
284280
{
285-
var delegateEntity = userDataService.GetDelegateById(delegateId);
281+
var delegateEntity = userService.GetDelegateById(delegateId);
286282
if (delegateEntity != null)
287283
{
288-
userDataService.DeleteUserCentreDetail(delegateEntity.DelegateAccount.UserId, delegateEntity.DelegateAccount.CentreId);
284+
userService.DeleteUserCentreDetail(delegateEntity.DelegateAccount.UserId, delegateEntity.DelegateAccount.CentreId);
289285
}
290286
return RedirectToAction("Index", "Delegates", new { DelegateId = delegateId });
291287
}
@@ -303,7 +299,7 @@ public IActionResult RemoveCentreEmailConfirmation(ConfirmationViewModel confirm
303299
[Route("SuperAdmin/Delegates/{delegateId=0:int}/ApproveDelegate")]
304300
public IActionResult ApproveDelegate(int delegateId = 0)
305301
{
306-
userDataService.ApproveDelegateUsers(delegateId);
302+
userService.ApproveDelegateUsers(delegateId);
307303
TempData["DelegateId"] = delegateId;
308304
return RedirectToAction("Index", "Delegates", new { DelegateId = delegateId });
309305
}

DigitalLearningSolutions.Web/Services/UserService.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace DigitalLearningSolutions.Web.Services
99
using DigitalLearningSolutions.Data.DataServices.UserDataService;
1010
using DigitalLearningSolutions.Data.Exceptions;
1111
using DigitalLearningSolutions.Data.Models;
12+
using DigitalLearningSolutions.Data.Models.SuperAdmin;
1213
using DigitalLearningSolutions.Data.Models.User;
1314
using DigitalLearningSolutions.Data.Utilities;
1415
using DocumentFormat.OpenXml.Office2010.Excel;
@@ -158,6 +159,11 @@ void SetCentreEmail(
158159

159160
AdminUser? GetAdminUserById(int id);
160161
string GetUserDisplayName(int userId);
162+
(IEnumerable<SuperAdminDelegateAccount>, int) GetAllDelegates(
163+
string search, int offset, int rows, int? delegateId, string accountStatus, string lhlinkStatus, int? centreId, int failedLoginThreshold
164+
);
165+
void DeleteUserCentreDetail(int userId, int centreId);
166+
void ApproveDelegateUsers(params int[] ids);
161167
(IEnumerable<AdminEntity>, int) GetAllAdmins(
162168
string search, int offset, int rows, int? adminId, string userStatus, string role, int? centreId, int failedLoginThreshold
163169
);
@@ -867,6 +873,21 @@ public string GetUserDisplayName(int userId)
867873
return userDataService.GetUserDisplayName(userId);
868874
}
869875

876+
public (IEnumerable<SuperAdminDelegateAccount>, int) GetAllDelegates(string search, int offset, int rows, int? delegateId, string accountStatus, string lhlinkStatus, int? centreId, int failedLoginThreshold)
877+
{
878+
return userDataService.GetAllDelegates(search, offset, rows, delegateId, accountStatus, lhlinkStatus, centreId, failedLoginThreshold);
879+
}
880+
881+
public void DeleteUserCentreDetail(int userId, int centreId)
882+
{
883+
userDataService.DeleteUserCentreDetail(userId, centreId);
884+
}
885+
886+
public void ApproveDelegateUsers(params int[] ids)
887+
{
888+
userDataService.ApproveDelegateUsers(ids);
889+
}
890+
870891
public (IEnumerable<AdminEntity>, int) GetAllAdmins(string search, int offset, int rows, int? adminId, string userStatus, string role, int? centreId, int failedLoginThreshold)
871892
{
872893
return userDataService.GetAllAdmins(search, offset, rows, adminId, userStatus, role, centreId, failedLoginThreshold);

0 commit comments

Comments
 (0)