Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        /// <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);
        }