public static RecipeManagerData LoadData(string path) { using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { var serializer = new XmlSerializer(typeof(RecipeManagerData)); var starage = (RecipeManagerData)serializer.Deserialize(fileStream); List <Recipe> tmpRecipes = new List <Recipe>(); foreach (var itemRecipe in starage.Recipes) { IngredientContainer ingredients = new IngredientContainer(); Ingredient tmpIngredient; foreach (var itemIngredient in itemRecipe.Ingredients) { tmpIngredient = starage.Ingredients.FindLast(t => t.Name == itemIngredient.Name); ingredients.Add(tmpIngredient); } Group group = starage.Groups.FindLast(t => t.Name == itemRecipe.Group.Name); Recipe recipe = Recipe.Create(itemRecipe.Description, group, ingredients, itemRecipe.RecipeSteps).Value; tmpRecipes.Add(recipe); } starage.Recipes = tmpRecipes; return(starage); } }
private void addButton_Click(object sender, System.EventArgs e) { AddIngredientForm formIngr = new AddIngredientForm(_storage.GetIngredient()); formIngr.ShowDialog(); if (formIngr.DialogResult == System.Windows.Forms.DialogResult.OK) { if (formIngr.Ingredient != null) { _ingredient.Add(formIngr.Ingredient); } } }