/// <summary> /// This method invokes method for adding ingredient to recipe. /// </summary> public void AddIngredientExecute() { if (String.IsNullOrEmpty(Ingredient.IngredientName) || String.IsNullOrEmpty(Ingredient.Quantity.ToString()) || Ingredient.Quantity == 0) { MessageBox.Show("Please fill all fields.", "Notification"); } else if (IngredientList != null && (IngredientList.Where(x => x.IngredientName == Ingredient.IngredientName).Any() || AddedIngredientList.Where(x => x.IngredientName == Ingredient.IngredientName).Any())) { MessageBox.Show("You already added this ingredient.", "Notification"); } else { try { ingredients.AddIngredient(Ingredient, out int id); Ingredient.IngredientId = id; //add to collection of added ingredients AddedIngredientList.Add(Ingredient); //remove from collection of deleted ingredients DeletedIngredientList.Remove(Ingredient); //invokes method to update a list of ingredients IngredientList = ingredients.GetRecipeIngredients(Recipe); Ingredient = new vwIngredient(); Ingredient.RecipeId = Recipe.RecipeId; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
public void RemoveIngredientExecute() { try { if (Ingredient != null) { //invokes method to delete ingredient ingredients.DeleteIngredient(Ingredient); //removing from collection of added ingredients AddedIngredientList.Remove(Ingredient); //added to collection of deleted ingredients DeletedIngredientList.Add(Ingredient); //invokes method to update list of ingredients IngredientList = ingredients.GetRecipeIngredients(Recipe); Ingredient = new vwIngredient(); Ingredient.RecipeId = Recipe.RecipeId; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }