public void Add()
        {
            bool fileAdded = false;

            do
            {
                Console.WriteLine("Type name of product:\t");
                string productName = Console.ReadLine();

                string path = GetPath(productName);
                // Create productName.json file, Add all informations (Name, Kcal, Fat etc...) in json format.

                Console.WriteLine("Type kcal in 100g: ");
                decimal kcal = Decimal.Parse(Console.ReadLine());
                NewProduct = new Product(productName, kcal);
                JsonManager json = new JsonManager();
                json.SaveObject(NewProduct, path);
                if (json.SaveSucced())
                {
                    fileAdded = true;
                }
                else
                {
                    Console.WriteLine("Try again.");
                }
            } while (fileAdded == false);
        }
Esempio 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);
        }