Exemple #1
0
 private void ListOutput(IngredientStorage container)
 {
     for (int i = 0; i < container.Count(); i++)
     {
         listView1.Items.Add(container[i].Name);
     }
 }
Exemple #2
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);
            }
        }
        public static Result <Recipe> Create(string description, DishCategory group, IngredientStorage ingredients, string recipeSteps)
        {
            var errors = new List <string>();

            if (group is null)
            {
                errors.Add("Рецепт должен содержать категорию");
            }
            ;
            if (string.IsNullOrEmpty(description))
            {
                errors.Add("Описание не может быть пустым");
            }
            if (string.IsNullOrEmpty(recipeSteps))
            {
                errors.Add("Укажите шаги рецепта");
            }
            if (ingredients.Count() == 0)
            {
                errors.Add("Рецепт должен содержать ингредиенты");
            }

            if (errors.Any())
            {
                return(Result <Recipe> .Fail(errors));
            }

            var context = Regex.Replace(description, @"\s+", " ").Trim();

            return(Result <Recipe> .Success(new Recipe(context, group, ingredients, recipeSteps)));
        }
 protected Recipe(string description, DishCategory group, IngredientStorage ingredients, string recipeSteps)
 {
     Description = description;
     Group       = group;
     Ingredients = ingredients;
     RecipeSteps = recipeSteps;
 }
 public RecipeForm(ObjectStorage storage, Recipe recipe) : this(storage)
 {
     txtDescription.Text  = recipe.Description;
     SelectedGroup        = recipe.Group;
     _ingredient          = recipe.Ingredients;
     _ingredient.Changed += ingredient_Changed;
     ingredient_Changed(this, new EventArgs());
     txtSteps.Text = recipe.RecipeSteps;
 }
        public RecipeForm(ObjectStorage storage)
        {
            _storage = storage;
            InitializeComponent();
            groupListCmb();

            _ingredient          = new IngredientStorage();
            _ingredient.Changed += ingredient_Changed;
        }
Exemple #7
0
        private ObjectStorage()
        {
            _ingredient = new IngredientStorage();
            _recipe     = new RecipeContainer();
            _group      = new DishCategoryComposition();

            /*
             * //_group.Add(Group.Create("Пусто").Value);
             * _group.Add(Group.Create("Десерты").Value);
             * _group.Add(Group.Create("Основные блюда").Value);
             *
             * //_ingredient.Add(Ingredient.Create("Курица").Value);
             * _ingredient.Add(Ingredient.Create("Говядина").Value);
             * _ingredient.Add(Ingredient.Create("Лук").Value);
             *
             * var res = Recipe.Create(
             *  description: "КуриГов",
             *  group: _group[1],
             *  ingredients: new IngredientContainer(new List<Ingredient>() { _ingredient[0], _ingredient[1] }),
             *  recipeSteps: "Без понятия"
             *  );
             * _recipe.Add(res.Value);
             */
        }
Exemple #8
0
 public AddIngredientForm(IngredientStorage container)
 {
     InitializeComponent();
     _ingredients = container;
     ListOutput(_ingredients);
 }