From 3c09df35d8641f7a823f85cb195f52d414df2874 Mon Sep 17 00:00:00 2001 From: Sherif Olaboye Date: Wed, 27 Nov 2024 16:35:24 +0000 Subject: [PATCH 1/2] TD-4889 Resolving internal server error when nominating delegate to supervisor --- .../DataServices/RegistrationDataService.cs | 49 +++++++++++++++++++ .../SupervisorController/Supervisor.cs | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/DigitalLearningSolutions.Data/DataServices/RegistrationDataService.cs b/DigitalLearningSolutions.Data/DataServices/RegistrationDataService.cs index d6b229e721..2e9e42d35e 100644 --- a/DigitalLearningSolutions.Data/DataServices/RegistrationDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/RegistrationDataService.cs @@ -197,7 +197,56 @@ public int RegisterAdmin( isSupervisor = registrationModel.IsSupervisor, isNominatedSupervisor = registrationModel.IsNominatedSupervisor, }; + if (registrationModel.CategoryId == 0) + { + var adminUserIdwithCategoryIdIsNull = connection.QuerySingle( + @"INSERT INTO AdminAccounts + ( + UserID, + CentreID, + CategoryID, + IsCentreAdmin, + IsCentreManager, + Active, + IsContentCreator, + IsContentManager, + ImportOnly, + IsTrainer, + IsSupervisor, + IsNominatedSupervisor + ) + OUTPUT Inserted.ID + VALUES + ( + @userId, + @centreId, + NULL, + @isCentreAdmin, + @isCentreManager, + @active, + @isContentCreator, + @isContentManager, + @importOnly, + @isTrainer, + @isSupervisor, + @isNominatedSupervisor + )", + adminValues, + transaction + ); + connection.Execute( + @"INSERT INTO NotificationUsers (NotificationId, AdminUserId) + SELECT N.NotificationId, @adminUserIdwithCategoryIdIsNull + FROM Notifications N INNER JOIN NotificationRoles NR + ON N.NotificationID = NR.NotificationID + WHERE RoleID IN @roles AND AutoOptIn = 1", + new { adminUserIdwithCategoryIdIsNull, roles = registrationModel.GetNotificationRoles() }, + transaction + ); + transaction.Commit(); + return adminUserIdwithCategoryIdIsNull; + } var adminUserId = connection.QuerySingle( @"INSERT INTO AdminAccounts ( diff --git a/DigitalLearningSolutions.Web/Controllers/SupervisorController/Supervisor.cs b/DigitalLearningSolutions.Web/Controllers/SupervisorController/Supervisor.cs index e051d12737..11d8ab1e7d 100644 --- a/DigitalLearningSolutions.Web/Controllers/SupervisorController/Supervisor.cs +++ b/DigitalLearningSolutions.Web/Controllers/SupervisorController/Supervisor.cs @@ -1314,7 +1314,7 @@ public IActionResult ConfirmNominateSupervisor(SupervisorDelegateViewModel super supervisorDelegateDetail.DelegateUserID, (int)User.GetCentreId() ); - supervisorDelegate.SelfAssessmentCategory = supervisorDelegate.SelfAssessmentCategory == 0 ? adminUser.CategoryId.Value : supervisorDelegate.SelfAssessmentCategory; + supervisorDelegate.SelfAssessmentCategory = supervisorDelegate.SelfAssessmentCategory == 0 ? (adminUser.CategoryId.HasValue ? adminUser.CategoryId.Value : 0) : supervisorDelegate.SelfAssessmentCategory; var centreName = adminUser.CentreName; var adminRoles = new AdminRoles(false, false, true, false, false, false, false, false); From fbeaa0a030c6cd733150ed84134d0e2711c7ae19 Mon Sep 17 00:00:00 2001 From: Sherif Olaboye Date: Wed, 27 Nov 2024 17:00:29 +0000 Subject: [PATCH 2/2] TD-4889 Resolving internal server error when nominating delegate to supervisor --- .../DataServices/RegistrationDataService.cs | 56 ++----------------- 1 file changed, 5 insertions(+), 51 deletions(-) diff --git a/DigitalLearningSolutions.Data/DataServices/RegistrationDataService.cs b/DigitalLearningSolutions.Data/DataServices/RegistrationDataService.cs index 2e9e42d35e..ced09e50f3 100644 --- a/DigitalLearningSolutions.Data/DataServices/RegistrationDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/RegistrationDataService.cs @@ -197,56 +197,7 @@ public int RegisterAdmin( isSupervisor = registrationModel.IsSupervisor, isNominatedSupervisor = registrationModel.IsNominatedSupervisor, }; - if (registrationModel.CategoryId == 0) - { - var adminUserIdwithCategoryIdIsNull = connection.QuerySingle( - @"INSERT INTO AdminAccounts - ( - UserID, - CentreID, - CategoryID, - IsCentreAdmin, - IsCentreManager, - Active, - IsContentCreator, - IsContentManager, - ImportOnly, - IsTrainer, - IsSupervisor, - IsNominatedSupervisor - ) - OUTPUT Inserted.ID - VALUES - ( - @userId, - @centreId, - NULL, - @isCentreAdmin, - @isCentreManager, - @active, - @isContentCreator, - @isContentManager, - @importOnly, - @isTrainer, - @isSupervisor, - @isNominatedSupervisor - )", - adminValues, - transaction - ); - - connection.Execute( - @"INSERT INTO NotificationUsers (NotificationId, AdminUserId) - SELECT N.NotificationId, @adminUserIdwithCategoryIdIsNull - FROM Notifications N INNER JOIN NotificationRoles NR - ON N.NotificationID = NR.NotificationID - WHERE RoleID IN @roles AND AutoOptIn = 1", - new { adminUserIdwithCategoryIdIsNull, roles = registrationModel.GetNotificationRoles() }, - transaction - ); - transaction.Commit(); - return adminUserIdwithCategoryIdIsNull; - } + var adminUserId = connection.QuerySingle( @"INSERT INTO AdminAccounts ( @@ -268,7 +219,10 @@ OUTPUT Inserted.ID ( @userId, @centreId, - @categoryId, + CASE + WHEN @categoryID = 0 THEN NULL + ELSE @categoryID + END, @isCentreAdmin, @isCentreManager, @active,