Exemple #1
0
        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)
                {
                    IngredientStorage ingredients = new IngredientStorage();
                    Ingredient        tmpIngredient;
                    foreach (var itemIngredient in itemRecipe.Ingredients)
                    {
                        tmpIngredient = starage.Ingredients.FindLast(t => t.Name == itemIngredient.Name);
                        ingredients.Add(tmpIngredient);
                    }
                    DishCategory 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);
            }
        }
Exemple #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var createResult = Recipe.Create(txtDescription.Text, SelectedGroup, _ingredient, txtSteps.Text);

            if (!createResult.Succeeded)
            {
                MessageBox.Show(string.Join(Environment.NewLine, createResult.Errors), "Recipe creation error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Recipe       = createResult.Value;
                DialogResult = DialogResult.OK;
                Close();
            }
        }