public IActionResult Post(MealDTO dto) { try { Meal = ApiRepository.DtoToMeal(dto); mealData.Add(Meal); if (mealData.Commit() > 0) { return(CreatedAtAction("GetById", new { id = Meal.MealId }, Meal)); } } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest()); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } if (Meal.MealId > 0) { mealData.Update(Meal); } else { mealData.Add(Meal); Meal.ImgPath = "groceries.png"; Meal.Owner = User.Identity.Name; } mealData.Commit(); TempData["Message"] = "Meal saved!"; return(RedirectToPage("./Details", new { mealId = Meal.MealId })); }