public async Task AddIngredient_Returns_Name_Of_Ingredient()
        {
            var ingredientName = await _ingredientService.AddIngredient(
                new IngredientDTO { Name = _ingredientName });

            Assert.Equal(_ingredientName, ingredientName);
        }
Ejemplo n.º 2
0
        public IActionResult AddIngredients(List <IngredientModel> ingredients)
        {
            foreach (var ingredient in ingredients)
            {
                ingredientService.AddIngredient(ingredient);
            }

            return(Ok(ingredients.Count));
        }
Ejemplo n.º 3
0
 public IActionResult AddIngredient([FromBody] Ingredient ingredient)
 {
     if (_ingredientService.AddIngredient(ingredient))
     {
         return(CreatedAtRoute("GetIngredient", new { ingredientId = ingredient.Id }, ingredient));
     }
     else
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 4
0
        public async Task <ActionResult <Ingredient> > AddIngredient(Ingredient ingredient)
        {
            try
            {
                Ingredient returned = await ingredientService.AddIngredient(ingredient);

                return(Ok(returned));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(StatusCode(500, e.Message));
            }
        }
Ejemplo n.º 5
0
        public ActionResult AddIngredient(IngredientViewModel ingredientViewModel)
        {
            if (ingredientViewModel == null)
            {
                return(BadRequest("Ingredient cannot be null."));
            }

            var ingredient = new Ingredient
            {
                Name        = ingredientViewModel.Name,
                Description = ingredientViewModel.Description
            };


            _ingredientService.AddIngredient(ingredient);
            return(StatusCode(201));
        }
Ejemplo n.º 6
0
        public IActionResult PostIngredient([FromBody] IngredientPlDto ingredient)
        {
            if (!ModelState.IsValid)
            {
                return(StatusCode(400, "Model is not valid"));
            }

            try
            {
                ingredient.IngredientId = Guid.NewGuid();
                var newIngredient = mapper.Map <BlDto_Ingredient>(ingredient);
                ingredientService.AddIngredient(newIngredient);

                return(StatusCode(201, "Author was added"));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, "Internal server error. Author is not added. Exception message: " + ex));
            }
        }
Ejemplo n.º 7
0
        private async Task NewIngredient()
        {
            ConsoleHelper.ColorWrite("What ingredient would you like to add: ");
            var name = Console.ReadLine();

            IngredientDTO newIngreditent = new IngredientDTO {
                Name = name
            };

            try
            {
                await _ingredientService.AddIngredient(newIngreditent);
            }
            catch (KeyNotFoundException)
            {
                ConsoleHelper.ColorWriteLine(ConsoleColor.DarkYellow, $"{name} already exists.");
            }

            Console.WriteLine();
            await this.Show();
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Add([FromBody] AddIngredientRequestModel addIngredient)
        {
            await _ingredientService.AddIngredient(addIngredient);

            return(Ok());
        }