async public Task RunAsync() { var userToDelete = await dbContext.Users.Where(u => u.UserName == userToDeleteName).Select(u => new { u.Id, u.UserName }).SingleAsync(); var userDeckIds = await dbContext.Decks.Where(d => d.Owner.Id == userToDelete.Id).Select(d => d.Id).ToListAsync(); var userCardsInDecksCount = await dbContext.CardsInDecks.Where(cardInDeck => cardInDeck.Deck.Owner.Id == userToDelete.Id).CountAsync(); var userCardRatingCount = await dbContext.UserCardRatings.Where(rating => rating.UserId == userToDelete.Id).CountAsync(); var userSearchSubscriptionIds = await dbContext.SearchSubscriptions.Where(subscription => subscription.UserId == userToDelete.Id).Select(subscription => subscription.Id).ToListAsync(); var userPrivateCardIds = await dbContext.Cards.Where(card => card.UsersWithView.Count() == 1 && card.UsersWithView.Any(userWithView => userWithView.UserId == userToDelete.Id)).Select(card => card.Id).ToListAsync(); logger.LogInformation($"Deleting user '{userToDelete.UserName}', id: {userToDelete.Id}"); logger.LogInformation($"User has {userDeckIds.Count} decks containing a total of {userCardsInDecksCount} cards"); logger.LogInformation($"User has recorded {userCardRatingCount} ratings"); logger.LogInformation($"User has {userSearchSubscriptionIds.Count} search subscriptions"); logger.LogInformation($"User has {userPrivateCardIds.Count} private cards"); logger.LogWarning("Please confirm again"); Engine.GetConfirmationOrCancel(logger); var adminUserId = await dbContext.Users.Where(u => u.UserName == adminUserName).Select(u => u.Id).SingleAsync(); var deleter = new DeleteUserAccount(dbContext.AsCallContext(new ProdRoleChecker(userManager)), userManager); await deleter.RunAsync(new DeleteUserAccount.Request(adminUserId, userToDelete.Id)); logger.LogInformation($"Deletion finished"); }
public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } RequirePassword = await _userManager.HasPasswordAsync(user); if (RequirePassword) { if (!await _userManager.CheckPasswordAsync(user, Input.Password)) { ModelState.AddModelError(string.Empty, "Incorrect password."); return(Page()); } } var deleter = new DeleteUserAccount(callContext, _userManager); await deleter.RunAsync(new DeleteUserAccount.Request(user.Id, user.Id)); await _signInManager.SignOutAsync(); _logger.LogInformation("User with ID '{UserId}' deleted themselves.", user.Id); return(Redirect("~/")); }
/// <summary> /// Provides the Delete request for the 'UserAccounts' resource. /// </summary> public DeleteUserAccountResponse Delete(DeleteUserAccount body) { return(ProcessRequest(body, HttpStatusCode.Accepted, () => { var response = this.UserAccountsManager.DeleteUserAccount(this.Request, body); return response; })); }
public void WhenAllPropertiesValid_ThenSucceeds() { var dto = new DeleteUserAccount { Id = "avalue", }; validator.ValidateAndThrow(dto); }
public void WhenIdIsNull_ThenThrows() { var dto = new DeleteUserAccount { Id = null, }; Assert.Throws <ValidationException>(FluentValidation <DeleteUserAccount> .NotEmptyErrorMessage(x => x.Id), () => validator.ValidateAndThrow(dto)); }
DeleteUserAccountResponse IUserAccountsManager.DeleteUserAccount(IRequest request, DeleteUserAccount body) { DeleteUserAccount(request.GetCurrentUser(), body.Id); return(new DeleteUserAccountResponse()); }