public async Task AddIngredient_Returns_Name_Of_Ingredient() { var ingredientName = await _ingredientService.AddIngredient( new IngredientDTO { Name = _ingredientName }); Assert.Equal(_ingredientName, ingredientName); }
public IActionResult AddIngredients(List <IngredientModel> ingredients) { foreach (var ingredient in ingredients) { ingredientService.AddIngredient(ingredient); } return(Ok(ingredients.Count)); }
public IActionResult AddIngredient([FromBody] Ingredient ingredient) { if (_ingredientService.AddIngredient(ingredient)) { return(CreatedAtRoute("GetIngredient", new { ingredientId = ingredient.Id }, ingredient)); } else { return(BadRequest()); } }
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)); } }
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)); }
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)); } }
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(); }
public async Task <IActionResult> Add([FromBody] AddIngredientRequestModel addIngredient) { await _ingredientService.AddIngredient(addIngredient); return(Ok()); }