Example #1
0
        private int GetLastIdCategory(string path)
        {
            JsonDishRepository dishRepository   = new JsonDishRepository();
            CollectionRecipe   collectionRecipe = new CollectionRecipe();

            collectionRecipe = dishRepository.Read(path);

            int buf = collectionRecipe.ListRecipe.Count - 1;

            return(collectionRecipe.ListRecipe[buf].Id);
        }
        public Recipe ShowOneRecipe(int choise)
        {
            JsonDishRepository fileWork      = new JsonDishRepository();
            CollectionRecipe   collectionBuf = new CollectionRecipe();

            collectionBuf = fileWork.Read(path);

            if (choise < 0 || choise > collectionBuf.ListRecipe.Count)
            {
                throw new Exception("invalid input in ShowOneRecipe.BL");
            }
            else
            {
                return(collectionBuf.ListRecipe[choise]);
            }
        }
        public CollectionRecipe ShowAllName()
        {
            JsonDishRepository fileWork      = new JsonDishRepository();
            CollectionRecipe   collectionBuf = new CollectionRecipe();
            CollectionRecipe   allName       = new CollectionRecipe();

            collectionBuf      = fileWork.Read(path);
            allName.ListRecipe = new List <Recipe>();

            for (int i = 0; i < collectionBuf.ListRecipe.Count; i++)
            {
                Recipe test = new Recipe();
                test.Name = collectionBuf.ListRecipe[i].Name;
                allName.ListRecipe.Add(test);
            }
            return(allName);
        }
        public bool AddRecipe(Recipe recipe)
        {
            Console.WriteLine(recipe.Ingredients.Values);
            Console.WriteLine(recipe.Ingredients.Keys);
            //возможность добавить проверки в будущем
            if (true)
            {
                CollectionRecipe   dishes         = new CollectionRecipe();
                JsonDishRepository jsonRepository = new JsonDishRepository();
                Id id = new Id(path);

                recipe.Id = id.id + 1;

                dishes = jsonRepository.Read(path);
                dishes.ListRecipe.Add(recipe);

                jsonRepository.Update(path, dishes);

                return(true);
            }
        }