public async Task <ActionResult> EditUser(EditUserModel model) { if (!ModelState.IsValid) { return(EditUser(model.UserId)); } var result = await _editUserCommand.Execute(model, UserManager); if (!result.Succeeded) { AddErrors(result); return(EditUser(model.UserId)); } var loggedInUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); if (model.UserId == loggedInUserId) { var user = _getAdminAppUserByIdQuery.Execute(model.UserId); if (user != null) { await SignInManager.SignInAsync(user, isPersistent : false); } } return(RedirectToActionJson <GlobalSettingsController>(x => x.Users(), "User updated successfully.")); }
public async Task ShouldEditUser() { ResetUsers(); var existingUsers = SetupUsers(2).ToList(); var userToBeEdited = existingUsers[0]; var userNotToBeEdited = existingUsers[1]; var guidString = Guid.NewGuid().ToString("N"); var updateModel = new EditUserModel { Email = $"test{guidString}@test.com", UserId = userToBeEdited.Id }; await ScopedAsync <UserManager <AdminAppUser> >(async manager => { var command = new EditUserCommand(); await command.Execute(updateModel, manager); var editedUser = Query(userToBeEdited.Id); editedUser.UserName.ShouldBe(updateModel.Email); editedUser.Email.ShouldBe(updateModel.Email); var notEditedUser = Query(userNotToBeEdited.Id); notEditedUser.UserName.ShouldBe(userNotToBeEdited.UserName); notEditedUser.Email.ShouldBe(userNotToBeEdited.Email); }); }