Пример #1
0
 /// <summary>
 /// Convert a meal creation DTO to a meal model.
 /// </summary>
 /// <param name="mealCreation">The meal creation DTO.</param>
 /// <returns>The meal model.</returns>
 public Domain.Meal ToModel(MealCreation mealCreation)
 {
     return(new Domain.Meal
            (
                id: 0,
                mealName: new Domain.Values.MealName(mealCreation.Name),
                ingredients: ToModel(mealCreation.MealIngredients),
                instructions: new Domain.Values.CookingInstructions(mealCreation.Instructions),
                servingSize: new Domain.Values.ServingSize(mealCreation.FeedsNumPeople)
            ));
 }
Пример #2
0
        public ActionResult <Meal> Post([FromBody] MealCreation meal)
        {
            Domain.Meal mealModel;
            try
            {
                mealModel = _dtoConverter.ToModel(meal);
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }

            _mealService.AddMeal(ref mealModel);
            return(CreatedAtRoute("Meals_GetSingle", new { id = mealModel.Id }, mealModel));
        }