public async Task DeleteConfirmed(string id) { try { await _usuarioServices.DeleteAsync(id); } catch (Exception ex) { throw ex; } }
public async Task <ActionResult <UsuarioModel> > DeleteUsuarioModel(string id) { if (id == null) { return(NotFound()); } var usuarioModel = await _usuarioServices.GetByIdAsync(id); if (usuarioModel == null) { return(NotFound()); } await _usuarioServices.DeleteAsync(id); return(Ok(usuarioModel)); }
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 userId = await _userManager.GetUserIdAsync(user); using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); var result = await _userManager.DeleteAsync(user); if (!result.Succeeded) { throw new InvalidOperationException( $"Unexpected error occurred deleting user with ID '{userId}'."); } await _usuarioServices.DeleteAsync(user.Id); scope.Complete(); await _signInManager.SignOutAsync(); _logger.LogInformation("User with ID '{UserId}' deleted themselves.", userId); return(Redirect("~/")); }