public void AddIngredientToRecipe_IngredientFoundRecipeNotFound_ReturnsFalse() { var ingredient = new Ingredient() { Name = "Beef" }; //add the ingredient to the database var ingredientRepository = new IngredientRepository(Context); ingredientRepository.Add(ingredient); var foundIngredient = ingredientRepository.GetAll().ToList(); //there should only be one added record in the database Assert.AreEqual(1, foundIngredient.Count()); //add an ingredient where recipe is not found and the ingredient is if (foundIngredient != null) { var added = ingredientRepository.AddIngredientToRecipe(456456, foundIngredient[0].IngredientId); //should return false Assert.IsFalse(added); } }
public async Task <Ingredient> GetOrAddIfNotExistsAndGet(Ingredient ingredient) { if (ingredient.PolishName == null) { return(null); } ingredient.PolishName = ingredient.PolishName.ToLower(); var ing = await _ingredientRepository.GetByName(ingredient.PolishName); if (ing != null) { ing.HazardStatements = await GetHazardStatemensList(ing.Id); return(ing); } else { ing = await _pubChemService.AutoComplete(ingredient); if (ing == null) { return(null); } var newIngredient = await _ingredientRepository.Add(ing); await AddRelationsToHazardStatements(newIngredient.Id, ing.HazardStatements); newIngredient.HazardStatements = ing.HazardStatements; return(newIngredient); } }
public async Task <ActionResult <Ingredient> > Add(Ingredient ingredient) { if (_ingredientRepository.GetByName(ingredient.PolishName) != null) { return(Conflict()); } ingredient.PolishName = ingredient.PolishName.ToLower(); var _ingredient = await _ingredientRepository.Add(ingredient); if (_ingredient == null) { return(NotFound()); } return(_ingredient); }
public void AddIngrident() { //create the ingredient var ingredient = new Ingredient() { Name = "Whole Chicken" }; //add the new ingredient to the database ingredientRepository.Add(ingredient); //find the added ingredient var foundIngredient = ingredientRepository.GetAll().ToList(); //if found check to see if the names are matching if (foundIngredient != null) { Assert.AreEqual(ingredient.Name, foundIngredient[0].Name); } }
public int AddIngredient([FromBody] Ingredient ingredient) { var existingIngredient = ingredientRepository.GetByName(ingredient.Name); if (existingIngredient != null) { return(1); } if (ingredient.Name == null || !ingredient.Name.Any(character => char.IsLetter(character))) { return(2); } ingredientRepository.Add(ingredient); return(0); }
/// <summary> /// Method to add an ingredient to the database /// </summary> /// <param name="ingredient">the ingredient object to be added</param> /// <returns>True if added to the database</returns> public async Task <bool> AddIngredientAsync(IngredientDTO ingredient) { var isAdded = true; try { var ingredientToBeAdded = CreateIngredientEntity(ingredient); await Task.Run(() => ingredientRepository.Add(ingredientToBeAdded)); } catch (Exception ex) { isAdded = false; // TODO:Add logging } return(isAdded); }
public ActionResult AddIngredient(AddIngredientModel model) { _ingredientRepository.Add(model.Name); return(RedirectToAction("Ingredients", "List")); }
public void Add(IngredientModel ingredientModel) { var ingredientToAdd = _ingredientMapper.MapIngredientModelToIngredientEntity(ingredientModel); _ingredientRepository.Add(ingredientToAdd); }
public void Add(Ingredient ingredient) { _repo.Add(ingredient); }