public ActionResult <Ingredient> Post([FromBody] IngredientCreation newIngredient)
        {
            var newIngredientModel = _dtoConverter.ToModel(newIngredient);
            var added = _mealService.AddIngredient(newIngredientModel);

            if (added)
            {
                var createdIngredient = _dtoConverter.ToDto(newIngredientModel);
                return(CreatedAtRoute("Ingredients_GetSingle", new { name = createdIngredient.Name }, createdIngredient));
            }
            else
            {
                return(Conflict($"Ingredient with name \"{newIngredientModel.Id.Name}\" already exists."));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Convert an ingredient creation DTO to an ingredient model.
        /// </summary>
        /// <param name="ingredientCreation">The ingredient creation DTO.</param>
        /// <returns>The ingredient model.</returns>
        public Domain.Ingredient ToModel(IngredientCreation ingredientCreation)
        {
            var uri = null != ingredientCreation.ImageUrl ? new Domain.Values.ImageUri(ingredientCreation.ImageUrl) : null;

            return(new Domain.Ingredient(new Domain.IngredientId(ingredientCreation.Name), ingredientCreation.Description, uri));
        }