public async Task <IActionResult> Delete(DeleteViewModel model) { if (ModelState.IsValid) { ApplicationUser user = await _userManager.GetUserAsync(User); var passwordIsValid = await _userManager.CheckPasswordAsync(user, model.Password); if (passwordIsValid) { await _signInManager.SignOutAsync(); IdentityResult result = await _userManager.DeleteAsync(user); if (result.Succeeded) { var filePaths = new List <string>(); if (user.ImageUri != null) { filePaths.Add($"users/{user.Id}/{user.ImageUri}"); } var recipeUris = await _recipeService.GetAllImageUrisAsync(user.Id); if (recipeUris.Any()) { filePaths.AddRange(recipeUris.Select(uri => $"users/{user.Id}/recipes/{uri}")); await _cdnService.DeleteUserResourcesAsync(user.Id, filePaths); } return(RedirectToAction(nameof(AccountController.Login), new { alert = LoginAlert.AccountDeleted })); } else { ModelState.AddModelError(string.Empty, _localizer["AnErrorOccurred"]); } } else { ModelState.AddModelError(string.Empty, _localizer["IncorrectPassword"]); } } return(View(model)); }