Skip to content

Commit 716cc6f

Browse files
authored
Merge pull request #2150 from TechnologyEnhancedLearning/Develop/Fixes/TD-2523-Super-admin-Delegate-page-doesn't-load-and-results-in-time-out-error
TD- 2523 super admin delegate page doesn't load and results in time out error
2 parents 49013d4 + 1ffb504 commit 716cc6f

File tree

4 files changed

+82
-49
lines changed

4 files changed

+82
-49
lines changed

DigitalLearningSolutions.Data/DataServices/UserDataService/UserDataService.cs

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.Extensions.Logging;
1313
using DocumentFormat.OpenXml.Wordprocessing;
1414
using System.Threading.Tasks;
15+
using DigitalLearningSolutions.Data.Models.SuperAdmin;
1516

1617
public interface IUserDataService
1718
{
@@ -239,7 +240,7 @@ int centreId
239240
(IEnumerable<AdminEntity>, int) GetAllAdmins(
240241
string search, int offset, int rows, int? adminId, string userStatus, string role, int? centreId, int failedLoginThreshold
241242
);
242-
(IEnumerable<DelegateEntity>, int) GetAllDelegates(
243+
(IEnumerable<SuperAdminDelegateAccount>, int) GetAllDelegates(
243244
string search, int offset, int rows, int? delegateId, string accountStatus, string lhlinkStatus, int? centreId, int failedLoginThreshold
244245
);
245246
Task<IEnumerable<AdminEntity>> GetAllAdminsExport(
@@ -588,7 +589,7 @@ public void UpdateUserDetailsAccount(string firstName, string lastName, string p
588589
new { trimmedFirstName, trimmedLastName, primaryEmail, jobGroupId, prnNumber, emailVerified, userId }
589590
);
590591
}
591-
public (IEnumerable<DelegateEntity>, int) GetAllDelegates(
592+
public (IEnumerable<SuperAdminDelegateAccount>, int) GetAllDelegates(
592593
string search, int offset, int rows, int? delegateId, string accountStatus, string lhlinkStatus, int? centreId, int failedLoginThreshold
593594
)
594595
{
@@ -608,30 +609,30 @@ public void UpdateUserDetailsAccount(string firstName, string lastName, string p
608609
da.SelfReg,
609610
da.UserID,
610611
da.RegistrationConfirmationHash,
611-
u.ID,
612-
u.PrimaryEmail,
612+
u.ID as UserId,
613+
COALESCE(ucd.Email, u.PrimaryEmail) AS EmailAddress,
613614
u.FirstName,
614615
u.LastName,
615-
u.Active,
616+
u.Active as UserActive,
616617
u.LearningHubAuthID,
617618
u.EmailVerified,
618619
ucd.ID,
619620
ucd.UserID,
620621
ucd.CentreID,
621-
ucd.Email,
622+
ucd.Email as CentreEmail,
622623
ucd.EmailVerified,
623624
(SELECT ID
624625
FROM AdminAccounts aa
625626
WHERE aa.UserID = da.UserID
626627
AND aa.CentreID = da.CentreID
627628
AND aa.Active = 1
628629
) AS AdminID
629-
FROM DelegateAccounts AS da
630-
INNER JOIN Centres AS ce ON ce.CentreId = da.CentreID
631-
INNER JOIN Users AS u ON u.ID = da.UserID
632-
LEFT JOIN UserCentreDetails AS ucd ON ucd.UserID = u.ID
630+
FROM DelegateAccounts AS da WITH (NOLOCK)
631+
INNER JOIN Centres AS ce WITH (NOLOCK) ON ce.CentreId = da.CentreID
632+
INNER JOIN Users AS u WITH (NOLOCK) ON u.ID = da.UserID
633+
LEFT JOIN UserCentreDetails AS ucd WITH (NOLOCK) ON ucd.UserID = u.ID
633634
AND ucd.CentreId = da.CentreID
634-
INNER JOIN JobGroups AS jg ON jg.JobGroupID = u.JobGroupID";
635+
INNER JOIN JobGroups AS jg WITH (NOLOCK) ON jg.JobGroupID = u.JobGroupID";
635636
string condition = $@" WHERE ((@delegateId = 0) OR (da.ID = @delegateId)) AND (u.FirstName + ' ' + u.LastName + ' ' + u.PrimaryEmail + ' ' + COALESCE(ucd.Email, '') + ' ' + COALESCE(da.CandidateNumber, '') LIKE N'%' + @search + N'%')
636637
AND ((ce.CentreID = @centreId) OR (@centreId= 0))
637638
AND ((@accountStatus = 'Any') OR (@accountStatus = 'Active' AND da.Active = 1 AND u.Active =1) OR (@accountStatus = 'Inactive' AND (u.Active = 0 OR da.Active =0))
@@ -642,28 +643,20 @@ FROM DelegateAccounts AS da
642643
string sql = @$"{BaseSelectQuery}{condition} ORDER BY LTRIM(u.LastName), LTRIM(u.FirstName)
643644
OFFSET @offset ROWS
644645
FETCH NEXT @rows ROWS ONLY";
645-
IEnumerable<DelegateEntity> delegateEntity =
646-
connection.Query<DelegateAccount, UserAccount, UserCentreDetails, int?, DelegateEntity>(
646+
IEnumerable<SuperAdminDelegateAccount> delegateEntity = connection.Query<SuperAdminDelegateAccount>(
647647
sql,
648-
(delegateAccount, userAccount, userCentreDetails, adminId) => new DelegateEntity(
649-
delegateAccount,
650-
userAccount,
651-
userCentreDetails,
652-
adminId
653-
),
654-
new { delegateId, search, centreId, accountStatus, lhlinkStatus, offset, rows },
655-
splitOn: "ID,ID,AdminID",
648+
new { delegateId, search, centreId, accountStatus, lhlinkStatus, offset, rows },
656649
commandTimeout: 3000
657650
);
658651

659652
int ResultCount = connection.ExecuteScalar<int>(
660653
@$"SELECT COUNT(*) AS Matches
661-
FROM DelegateAccounts AS da
662-
INNER JOIN Centres AS ce ON ce.CentreId = da.CentreID
663-
INNER JOIN Users AS u ON u.ID = da.UserID
664-
LEFT JOIN UserCentreDetails AS ucd ON ucd.UserID = u.ID
654+
FROM DelegateAccounts AS da WITH (NOLOCK)
655+
INNER JOIN Centres AS ce WITH (NOLOCK) ON ce.CentreId = da.CentreID
656+
INNER JOIN Users AS u WITH (NOLOCK) ON u.ID = da.UserID
657+
LEFT JOIN UserCentreDetails AS ucd WITH (NOLOCK) ON ucd.UserID = u.ID
665658
AND ucd.CentreId = da.CentreID
666-
INNER JOIN JobGroups AS jg ON jg.JobGroupID = u.JobGroupID {condition}",
659+
INNER JOIN JobGroups AS jg WITH (NOLOCK) ON jg.JobGroupID = u.JobGroupID {condition}",
667660
new { delegateId, search, centreId, accountStatus, failedLoginThreshold, lhlinkStatus },
668661
commandTimeout: 3000
669662
);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using DigitalLearningSolutions.Data.Models.User;
2+
using Serilog.Debugging;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace DigitalLearningSolutions.Data.Models.SuperAdmin
10+
{
11+
public class SuperAdminDelegateAccount:DelegateUser
12+
{
13+
public SuperAdminDelegateAccount() { }
14+
public SuperAdminDelegateAccount(DelegateEntity delegateEntity) {
15+
Id = delegateEntity.DelegateAccount.Id;
16+
FirstName = delegateEntity.UserAccount.FirstName;
17+
LastName = delegateEntity.UserAccount.LastName;
18+
EmailAddress = delegateEntity.UserCentreDetails?.Email ?? delegateEntity.UserAccount.PrimaryEmail;
19+
UserId = delegateEntity.DelegateAccount.UserId;
20+
CentreName = delegateEntity.DelegateAccount.CentreName;
21+
CentreEmail = delegateEntity.UserCentreDetails?.Email;
22+
CandidateNumber = delegateEntity.DelegateAccount.CandidateNumber;
23+
LearningHubAuthId = delegateEntity.UserAccount.LearningHubAuthId;
24+
RegistrationConfirmationHash = delegateEntity.DelegateAccount.RegistrationConfirmationHash;
25+
DateRegistered = delegateEntity.DelegateAccount.DateRegistered;
26+
SelfReg = delegateEntity.DelegateAccount.SelfReg;
27+
Active = delegateEntity.DelegateAccount.Active;
28+
EmailVerified = delegateEntity.UserAccount.EmailVerified;
29+
UserActive = delegateEntity.UserAccount.Active;
30+
Approved = delegateEntity.DelegateAccount.Approved;
31+
32+
}
33+
public bool SelfReg { get; set; }
34+
public string? CentreEmail { get; set; }
35+
public int? LearningHubAuthId { get; set; }
36+
public bool UserActive { get; set; }
37+
}
38+
}

DigitalLearningSolutions.Web/ViewModels/SuperAdmin/Delegates/DelegatesViewModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
{
33
using DigitalLearningSolutions.Data.Helpers;
44
using DigitalLearningSolutions.Data.Models.SearchSortFilterPaginate;
5+
using DigitalLearningSolutions.Data.Models.SuperAdmin;
56
using DigitalLearningSolutions.Data.Models.User;
67
using DigitalLearningSolutions.Web.Models.Enums;
78
using DigitalLearningSolutions.Web.ViewModels.Common.SearchablePage;
89
using System.Collections.Generic;
910
using System.Linq;
10-
public class DelegatesViewModel : BaseSearchablePageViewModel<DelegateEntity>
11+
public class DelegatesViewModel : BaseSearchablePageViewModel<SuperAdminDelegateAccount>
1112
{
1213
public DelegatesViewModel(
13-
SearchSortFilterPaginationResult<DelegateEntity> result
14+
SearchSortFilterPaginationResult<SuperAdminDelegateAccount> result
1415
) : base(
1516
result,
1617
true,
@@ -21,7 +22,7 @@ SearchSortFilterPaginationResult<DelegateEntity> result
2122
Delegates = result.ItemsToDisplay.Select(
2223
delegates => new SearchableDelegatesViewModel(
2324
delegates,
24-
result.GetReturnPageQuery($"{delegates.DelegateAccount.Id}-card")
25+
result.GetReturnPageQuery($"{delegates.Id}-card")
2526
)
2627
);
2728
}

DigitalLearningSolutions.Web/ViewModels/SuperAdmin/Delegates/SearchableDelegatesViewModel.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace DigitalLearningSolutions.Web.ViewModels.SuperAdmin.Delegates
33
{
44
using DigitalLearningSolutions.Data.Helpers;
55
using DigitalLearningSolutions.Data.Models.SearchSortFilterPaginate;
6+
using DigitalLearningSolutions.Data.Models.SuperAdmin;
67
using DigitalLearningSolutions.Data.Models.User;
78
using DigitalLearningSolutions.Web.Helpers;
89
using DigitalLearningSolutions.Web.ViewModels.Common.SearchablePage;
@@ -11,29 +12,29 @@ public class SearchableDelegatesViewModel : BaseFilterableViewModel
1112
public readonly bool CanShowDeleteDelegateButton;
1213
public readonly bool CanShowInactivateDelegateButton;
1314
public SearchableDelegatesViewModel(
14-
DelegateEntity delegates,
15+
SuperAdminDelegateAccount delegates,
1516
ReturnPageQuery returnPageQuery
1617
)
1718
{
18-
Id = delegates.DelegateAccount.Id;
19-
Name = delegates.UserAccount?.FirstName + " " + delegates.UserAccount?.LastName;
20-
FirstName = delegates.UserAccount?.FirstName;
21-
LastName = delegates.UserAccount?.LastName;
22-
PrimaryEmail = delegates.UserAccount?.PrimaryEmail;
23-
UserAccountID = delegates.UserAccount.Id;
24-
Centre = delegates.DelegateAccount.CentreName;
25-
CentreEmail = delegates.UserCentreDetails?.Email;
26-
DelegateNumber = delegates.DelegateAccount.CandidateNumber;
27-
LearningHubID = delegates.UserAccount.LearningHubAuthId;
28-
AccountClaimed = delegates.DelegateAccount.RegistrationConfirmationHash;
29-
DateRegistered = delegates.DelegateAccount?.DateRegistered.ToString(Data.Helpers.DateHelper.StandardDateFormat);
30-
SelRegistered = delegates.DelegateAccount.SelfReg;
31-
IsDelegateActive = delegates.DelegateAccount.Active;
32-
IsCentreEmailVerified = delegates.UserAccount.EmailVerified == null ? false : true;
33-
CanShowInactivateDelegateButton = IsDelegateActive ;
34-
IsUserActive = delegates.UserAccount.Active;
35-
IsApproved = delegates.DelegateAccount.Approved;
36-
IsClaimed = delegates.DelegateAccount.RegistrationConfirmationHash == null ? true : false;
19+
Id = delegates.Id;
20+
Name = delegates.FirstName + " " + delegates.LastName;
21+
FirstName = delegates?.FirstName;
22+
LastName = delegates?.LastName;
23+
PrimaryEmail = delegates.EmailAddress;
24+
UserAccountID = delegates.UserId;
25+
Centre = delegates.CentreName;
26+
CentreEmail = delegates.CentreEmail;
27+
DelegateNumber = delegates.CandidateNumber;
28+
LearningHubID = delegates.LearningHubAuthId;
29+
AccountClaimed = delegates.RegistrationConfirmationHash;
30+
DateRegistered = delegates.DateRegistered?.ToString(Data.Helpers.DateHelper.StandardDateFormat);
31+
SelRegistered = delegates.SelfReg;
32+
IsDelegateActive = delegates.Active;
33+
IsCentreEmailVerified = delegates.EmailVerified == null ? false : true;
34+
CanShowInactivateDelegateButton = IsDelegateActive;
35+
IsUserActive = delegates.UserActive;
36+
IsApproved = delegates.Approved;
37+
IsClaimed = delegates.RegistrationConfirmationHash == null ? true : false;
3738
ReturnPageQuery = returnPageQuery;
3839
}
3940

0 commit comments

Comments
 (0)