@@ -197,9 +197,60 @@ public int RegisterAdmin(
197197 isSupervisor = registrationModel . IsSupervisor ,
198198 isNominatedSupervisor = registrationModel . IsNominatedSupervisor ,
199199 } ;
200+ if ( registrationModel . CategoryId == 0 )
201+ {
202+ var adminUserIdwithCategoryIdIsNull = connection . QuerySingle < int > (
203+ @"INSERT INTO AdminAccounts
204+ (
205+ UserID,
206+ CentreID,
207+ CategoryID,
208+ IsCentreAdmin,
209+ IsCentreManager,
210+ Active,
211+ IsContentCreator,
212+ IsContentManager,
213+ ImportOnly,
214+ IsTrainer,
215+ IsSupervisor,
216+ IsNominatedSupervisor
217+ )
218+ OUTPUT Inserted.ID
219+ VALUES
220+ (
221+ @userId,
222+ @centreId,
223+ NULL,
224+ @isCentreAdmin,
225+ @isCentreManager,
226+ @active,
227+ @isContentCreator,
228+ @isContentManager,
229+ @importOnly,
230+ @isTrainer,
231+ @isSupervisor,
232+ @isNominatedSupervisor
233+ )" ,
234+ adminValues ,
235+ transaction
236+ ) ;
200237
238+ connection . Execute (
239+ @"INSERT INTO NotificationUsers (NotificationId, AdminUserId)
240+ SELECT N.NotificationId, @adminUserIdwithCategoryIdIsNull
241+ FROM Notifications N INNER JOIN NotificationRoles NR
242+ ON N.NotificationID = NR.NotificationID
243+ WHERE RoleID IN @roles AND AutoOptIn = 1" ,
244+ new { adminUserIdwithCategoryIdIsNull , roles = registrationModel . GetNotificationRoles ( ) } ,
245+ transaction
246+ ) ;
247+ transaction . Commit ( ) ;
248+
249+ return adminUserIdwithCategoryIdIsNull ;
250+ }
201251 var adminUserId = connection . QuerySingle < int > (
202- @"INSERT INTO AdminAccounts
252+
253+ @"INSERT INTO AdminAccounts
203254 (
204255 UserID,
205256 CentreID,
@@ -230,9 +281,9 @@ OUTPUT Inserted.ID
230281 @isSupervisor,
231282 @isNominatedSupervisor
232283 )" ,
233- adminValues ,
234- transaction
235- ) ;
284+ adminValues ,
285+ transaction
286+ ) ;
236287
237288 connection . Execute (
238289 @"INSERT INTO NotificationUsers (NotificationId, AdminUserId)
@@ -243,7 +294,6 @@ FROM Notifications N INNER JOIN NotificationRoles NR
243294 new { adminUserId , roles = registrationModel . GetNotificationRoles ( ) } ,
244295 transaction
245296 ) ;
246-
247297 transaction . Commit ( ) ;
248298
249299 return adminUserId ;
0 commit comments