public ActionResult <MealItem> editMeal(int id, [FromBody] MealItem meal) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Check if id is valid if (mealDB.getMealItem(id) == null) { return(NotFound(($"No MealItem found for id: {id}"))); } //update existing item MealItem item_out = mealDB.saveNewMeal(meal); //return new item return(Ok(item_out)); }
/// <summary> /// Check if this MealItem already exist /// add FoundedID if exist /// else create new /// </summary> /// <param name="meal"></param> /// <returns></returns> private MealItem handleMealInput(MealItem meal) { int foundedMealID = mealDB.selectMealIDFromOtherInformation(meal); if (foundedMealID == 0) { meal = mealDB.saveNewMeal(meal); } else { meal.MealID = foundedMealID; } return(meal); }