public static void refreshDataFromXML() { _recipes = MyStorage.readXML <List <Recipe> >("recipes.xml"); _ingredients = MyStorage.readXML <ObservableCollection <Ingredient> >("ingredients.xml"); _shoppingCart = MyStorage.readXML <ObservableCollection <Ingredient> >("shoppingCart.xml"); _availableIngredients = new ObservableCollection <Ingredient>((from i in _ingredients where i.IngredientQty != 0 select i).ToList()); _allIngredients = new ObservableCollection <Ingredient>((from i in _ingredients where i.IngredientQty == 0 select i).ToList()); }
private void btn_addToCart_Click(object sender, RoutedEventArgs e) { foreach (Ingredient missingIngredient in _ingredientsAbsent) { if (App._shoppingCart != null) { Ingredient checkIfExists = (Ingredient)App._shoppingCart.SingleOrDefault(i => i.IngredientName.Equals(missingIngredient.IngredientName)); if (checkIfExists == null) { App._shoppingCart.Add(missingIngredient); } else { checkIfExists.IngredientQty = checkIfExists.IngredientQty + missingIngredient.IngredientQty; } } else { App._shoppingCart.Add(missingIngredient); } } MyStorage.storeXML <ObservableCollection <Ingredient> >(App._shoppingCart, "shoppingCart.xml"); MessageBox.Show("Ingredients successfully added to cart", "Success"); }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { MyStorage.storeXML <ObservableCollection <Ingredient> >(App._shoppingCart, "shoppingCart.xml"); }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { MyStorage.storeXML <List <Recipe> >(App._recipes, "recipes.xml"); }