Exemplo n.º 1
0
        public IActionResult CreateIngredient([FromBody] Ingredient ingredientToCreate)
        {
            if (ingredientToCreate == null)
            {
                return(BadRequest(ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!_ingredientRepository.CreateIngredient(ingredientToCreate))
            {
                ModelState.AddModelError("", $"Something went wrong saving the ingredient " +
                                         $"{ingredientToCreate.Name}");
                return(StatusCode(500, ModelState));
            }

            return(CreatedAtRoute("GetIngredient", new { ingredientId = ingredientToCreate.Id }, ingredientToCreate));
        }
Exemplo n.º 2
0
        //public IEnumerable<Ingredient> GetIngredients(int userId)
        //{
        //    DataTable dataTable = _ingredientRepository.GetIngredients(userId);
        //    return _ingredientMapper.HydrateIngredients(dataTable);
        //}

        public void CreateIngredient(string code, int mealId)
        {
            _ingredientRepository.CreateIngredient(code, mealId);
        }