public static Result <Recipe> Create(string description, Group group, IngredientContainer ingredients, string recipeSteps)
        {
            var errors = new List <string>();

            if (group is null)
            {
                errors.Add("The recipe must contain a group");
            }
            ;
            if (string.IsNullOrEmpty(description))
            {
                errors.Add("Description cannot be empty");
            }
            if (string.IsNullOrEmpty(recipeSteps))
            {
                errors.Add("Recipe steps must be specified");
            }
            if (ingredients.Count() == 0)
            {
                errors.Add("The recipe must contain ingredients");
            }

            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)));
        }
 private void ListOutput(IngredientContainer container)
 {
     for (int i = 0; i < container.Count(); i++)
     {
         listView1.Items.Add(container[i].Name);
     }
 }
 protected Recipe(string description, Group group, IngredientContainer ingredients, string recipeSteps)
 {
     Description = description;
     Group       = group;
     Ingredients = ingredients;
     RecipeSteps = recipeSteps;
 }
Esempio n. 4
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)
                {
                    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);
            }
        }
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
        public RecipeForm(ObjectStorage storage)
        {
            _storage = storage;
            InitializeComponent();
            groupListCmb();

            _ingredient          = new IngredientContainer();
            _ingredient.Changed += ingredient_Changed;
        }
        private ObjectStorage()
        {
            _ingredient = new IngredientContainer();
            _recipe     = new RecipeContainer();
            _group      = new GroupContainer();

            /*
             * //_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);
             */
        }
 public AddIngredientForm(IngredientContainer container)
 {
     InitializeComponent();
     _ingredients = container;
     ListOutput(_ingredients);
 }