public ActionResult <Ingredient> Put(string name, [FromBody] IngredientUpdate ingredientUpdate)
        {
            if (!_mealService.TryGetIngredient(name, out _))
            {
                return(NotFound($"Ingredient with name \"{name}\" does not exist."));
            }

            Domain.Ingredient ingredient;
            try
            {
                ingredient = _dtoConverter.ToModel(name, ingredientUpdate);
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }

            var updatedIngredient = _mealService.SaveIngredient(ingredient);

            return(_dtoConverter.ToDto(updatedIngredient));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Convert an ingredient update DTO to an ingredient model.
        /// </summary>
        /// <param name="ingredientName">The ingredient name.</param>
        /// <param name="ingredientUpdate">The ingredient update DTO.</param>
        /// <returns>The ingredient model.</returns>
        public Domain.Ingredient ToModel(string ingredientName, IngredientUpdate ingredientUpdate)
        {
            var uri = null != ingredientUpdate.ImageUrl ? new Domain.Values.ImageUri(ingredientUpdate.ImageUrl) : null;

            return(new Domain.Ingredient(new Domain.IngredientId(ingredientName), ingredientUpdate.Description, uri));
        }