public async Task ConfirmNewUserAsync(string userId, UserAndOrganizationDto userAndOrg) { var applicationUser = await _usersDbSet.FirstAsync(user => user.Id == userId); _userAdministrationValidator.CheckIfEmploymentDateIsSet(applicationUser.EmploymentDate); var hasRole = await _userManager.IsInRoleAsync(userId, Contracts.Constants.Roles.FirstLogin); _userAdministrationValidator.CheckIfUserHasFirstLoginRole(hasRole); var addRoleResult = await _userManager.AddToRoleAsync(userId, Contracts.Constants.Roles.User); var removeRoleResult = await _userManager.RemoveFromRoleAsync(userId, Contracts.Constants.Roles.NewUser); _userAdministrationValidator.CheckForAddingRemovingRoleErrors(addRoleResult.Errors.ToList(), removeRoleResult.Errors.ToList()); await _notificationService.SendConfirmedNotificationEmailAsync(applicationUser.Email, userAndOrg); SetTutorialStatus(applicationUser, false); await SetWelcomeKudosAsync(applicationUser); await AddUserToWallsForNewUsers(userAndOrg); await _uow.SaveChangesAsync(userAndOrg.UserId); }
public void ConfirmNewUser(string userId, UserAndOrganizationDTO userAndOrg) { var applicationUser = _usersDbSet.First(user => user.Id == userId); _userAdministrationValidator.CheckIfEmploymentDateIsSet(applicationUser.EmploymentDate); var hasRole = _userManager.IsInRole(userId, Constants.Authorization.Roles.FirstLogin); _userAdministrationValidator.CheckIfUserHasFirstLoginRole(hasRole); var addRoleResult = _userManager.AddToRole(userId, Constants.Authorization.Roles.User); var removeRoleResult = _userManager.RemoveFromRole(userId, Constants.Authorization.Roles.NewUser); _userAdministrationValidator.CheckForAddingRemovingRoleErrors(addRoleResult.Errors, removeRoleResult.Errors); _notificationService.SendConfirmedNotificationEmail(applicationUser.Email, userAndOrg); SetTutorialStatus(applicationUser, false); AddUserToMainWall(userId); _uow.SaveChanges(userAndOrg.UserId); }
public void Should_Throw_Exception_If_User_Has_Not_Filled_His_Info_Yet() { Assert.Throws <UserAdministrationException>(() => _userAdministrationValidator.CheckIfUserHasFirstLoginRole(true)); }