public void AddNewRecipe(Recipe recipe) { allRecipes.Add(recipe); }
public static System.Collections.ObjectModel.ObservableCollection<Recipe> getRecipes(string path) { System.Collections.ObjectModel.ObservableCollection<Recipe> allRecipes = new System.Collections.ObjectModel.ObservableCollection<Recipe>(); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(path); System.Xml.XmlNode RecipeList = doc.SelectSingleNode("RecipeBook"); System.Xml.XmlNodeList allRecipiesXML = RecipeList.SelectNodes("Recipe"); foreach (System.Xml.XmlNode nowRecipe in allRecipiesXML) { //string category_name = Convert.ToString(rec.Attributes.GetNamedItem("name").Value); //System.Xml.XmlNodeList currentRecipes = category.SelectNodes("Recipe"); //allRecipes.Add(new Tuple<string, List<Recipe>>(category_name, new List<Recipe>())); //foreach(System.Xml.XmlNode nowRecipe in currentRecipes) //{ Recipe recipe = new Recipe(); recipe.Category = nowRecipe.SelectSingleNode("Category").InnerText; recipe.Title = nowRecipe.SelectSingleNode("Title").InnerText; recipe.Ingredients = nowRecipe.SelectSingleNode("Ingredients").InnerText; recipe.WayToCook = nowRecipe.SelectSingleNode("WayToCook").InnerText; System.Xml.XmlNode ttc = nowRecipe.SelectSingleNode("TimeToCook"); if (ttc != null) recipe.TimeToCook = ttc.InnerText; System.Xml.XmlNode aut = nowRecipe.SelectSingleNode("Author"); if (aut != null) recipe.Author = aut.InnerText; allRecipes.Add(recipe); //} } return allRecipes; }
private void RecipeSelectedEventHandler(object sender, RoutedEventArgs e) { ListBoxItem lib = sender as ListBoxItem; Recipe rep = lib.Content as Recipe; TextBox tb = this.FindName("RecipeDescriptionTextBox") as TextBox; tb.Text = rep.Title; tb.Text += " " + LocalizationManager.Instance.getStringForKey("BY") + " " + rep.Author; tb.Text += System.Environment.NewLine; tb.Text += System.Environment.NewLine; tb.Text += LocalizationManager.Instance.getStringForKey("TIME_TO_COOK") + ": "; tb.Text += rep.TimeToCook; tb.Text += System.Environment.NewLine; tb.Text += System.Environment.NewLine; tb.Text += LocalizationManager.Instance.getStringForKey("INGREDIENTS") + ":" + System.Environment.NewLine; tb.Text += rep.Ingredients; tb.Text += System.Environment.NewLine; tb.Text += System.Environment.NewLine; tb.Text += LocalizationManager.Instance.getStringForKey("WAY_TO_COOK") + ":" + Environment.NewLine; tb.Text += rep.WayToCook; //activate edit and delete buttons MenuItem emi = this.FindName("EditRecipeButton") as MenuItem; MenuItem dmi = this.FindName("DeleteRecipeButton") as MenuItem; MenuItem pmi = this.FindName("PrintRecipeButton") as MenuItem; emi.IsEnabled = true; dmi.IsEnabled = true; pmi.IsEnabled = true; selectedRecipe = rep; }