public IActionResult Delete(int id) { try { Meal = mealData.GetById(id); if (Meal == null) { return(NotFound($"Could not find meal with id:{id}")); } mealData.Delete(id); if (mealData.Commit() > 0) { return(Ok()); } } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest("Failed to delete meal")); }
public IActionResult OnPost(int mealId) { Meal = mealData.Delete(mealId); mealData.Commit(); if (Meal != null) { return(RedirectToPage("./MealList")); } TempData["Message"] = $"{Meal.Name} deleted!"; return(RedirectToPage("./MealList")); }