Ejemplo 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);
                }
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        private List <Recipe> GetListFromDataBase(string kindOfRecipe)
        {
            AllRecipesList.Clear();

            if (kindOfRecipe == "All")
            {
                Folder = FolderStd + "LowCaloryfic/";
                GetDataFromFolder(Folder);
                Folder = FolderStd + "MediumCaloryfic/";
                GetDataFromFolder(Folder);
                Folder = FolderStd + "HighCaloryfic/";
                GetDataFromFolder(Folder);
            }
            else if (kindOfRecipe == "Low" || kindOfRecipe == "Medium" || kindOfRecipe == "High")
            {
                GetDataFromFolder(ChooseFolderByKind(kindOfRecipe));
            }
            else
            {
                Console.WriteLine($"Invalid input.");
            }
            Folder = FolderStd;
            return(AllRecipesList.OrderBy(recipe => recipe.Name).ToList());
        }