public async Task <IActionResult> PostIngredient([FromForm] Ingredient ingredient) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Ingredients.Add(ingredient); CurrentIngredient currentIngredient = new CurrentIngredient(ingredient); //POST: api/CurrentIngredient //_context.CurrentIngredient.Add(currentIngredient); await _context.SaveChangesAsync(); var jObject = Utils.getJObjectResponseFromObject(true, ingredient); return(CreatedAtAction("GetIngredient", new { id = ingredient.Id }, jObject)); }
/// <summary> /// CategoryPage Constructor /// </summary> /// /// <param name="Items"></param> /// ///<remarks> /// Takes in the Full list of Recipes and adds all the ingredients to a String Array. Then Initialises the Commands. /// </remarks> public CategoryPage(ObservableCollection <Recipe> Items) { InitializeComponent(); ingredientArray = new List <string>(); bool Exists = false; foreach (var item in Items) { foreach (var ingredient in item.IngredientList) { foreach (var CurrentIngredient in ingredientArray) { if (CurrentIngredient.Equals(ingredient.Name)) { Exists = true; } } if (!Exists) { ingredientArray.Add(ingredient.Name); } else { Exists = false; } } } NavigateCommand = new Command <string>(async(string mealType) => { await Navigation.PushAsync(new ItemsPage(mealType)); }); NavigateIngredientCommand = new Command <string>(async(string ingredient) => { await Navigation.PushAsync(new ItemsPage(ingredient, 1)); }); BindingContext = this; Title = "Search"; }