Exemplo n.º 1
0
        private void GetDataFromFolder(string folder)
        {
            Folder = folder;
            JsonManager json = new JsonManager();

            foreach (string file in Directory.GetFiles(Folder, "*.json"))
            {
                Recipe recipeX = (Recipe)json.LoadObject(file);
                if (recipeX != null)
                {
                    AllRecipesList.Add(recipeX);
                }
            }
        }
        public List <Product> GetAll()  // Working good
        {
            All.Clear();
            JsonManager json = new JsonManager();

            foreach (string file in Directory.GetFiles(Folder, "*" + Extention))
            {
                Product product = (Product)json.LoadObject(file);

                if (product != null)
                {
                    All.Add(product);
                }
            }
            return(All);
        }
Exemplo n.º 3
0
        private void AddRecipeToDataBase()
        {
            bool fileAdded = false;

            // Create productName.json file, Add all informations (Name, Kcal, Fat etc...) in json format.
            do
            {
                JsonManager json = new JsonManager();
                json.SaveObject(NewRecipe, GeneratePath(NewRecipe.Name));
                if (json.SaveSucced())
                {
                    fileAdded = true;
                    AllRecipesList.Add(NewRecipe);
                }
                else
                {
                    Console.WriteLine("Try again.");
                    NewRecipe.Name = Console.ReadLine();
                }
            } while (fileAdded == false);
        }