public async Task<IActionResult> OnPost(int recipeId) { var recipe = await repository.GetRecipeAsync(recipeId); if (recipe == null) return RedirectToPage("./NotFound"); repository.Delete(recipe); await repository.SaveChangesAsync(); TempData["Message"] = $"{recipe.Name} deleted."; return RedirectToPage("./List"); }
public async Task <IActionResult> OnPost(int productId) { var product = await repository.GetProductAsync(productId); if (product == null) { return(RedirectToPage("./NotFound")); } repository.Delete(product); await repository.SaveChangesAsync(); TempData["Message"] = $"{product.Name} deleted."; return(RedirectToPage("./List")); }
public async Task <ActionResult> Delete(int id) { var recipeToDelete = await repository.GetRecipeAsync(id); if (recipeToDelete == null) { return(NotFound($"Could not find recipe with id: {id}.")); } repository.Delete(recipeToDelete); if (await repository.SaveChangesAsync()) { return(Ok()); } else { return(BadRequest("Failed to delete the recipe.")); } }
public async Task <ActionResult> Delete(int id) { var productToDelete = await repository.GetProductAsync(id); if (productToDelete == null) { return(NotFound($"Could not find product with id: {id}.")); } repository.Delete(productToDelete); if (await repository.SaveChangesAsync()) { return(Ok()); } else { return(BadRequest("Failed to delete the product.")); } }