示例#1
0
        private static void MenuRecipesToView(Cookbook cookbook)
        {
            Console.WriteLine("\n1) Zobrazit všechny recepty");
            Console.WriteLine("2) Zobrazit recepty dle kategorie");
            Console.WriteLine("3) Zobrazit recepty dle ingredience");

            switch (AuxiliaryMethod.LoadNumberInRange("\nVyberte jednu z možností: ", 3))
            {
            case 1:
                ShowCertainRecipeFromList(cookbook, cookbook.Recipes);
                break;

            case 2:
                ShowCategories();
                Category category = (Category)(int)AuxiliaryMethod.LoadNumberInRange("Kterou kategorii chcete zobrazit?", 4);
                var      recipes  = CookbookConsoleUtility.FindRecipesByCategoryInCookbook(cookbook, category);
                ShowCertainRecipeFromList(cookbook, recipes);
                break;

            case 3:
                string ingredient          = AuxiliaryMethod.LoadStringFromConsole("Recepty s kterou ingrediencí chcete zobrazit?").ToLower();
                var    recipesByIngredient = CookbookConsoleUtility.FindRecipesByIngredientInCookbook(cookbook, ingredient);
                ShowCertainRecipeFromList(cookbook, recipesByIngredient);
                break;

            default:
                CookbookConsoleUtility.ViewRecipes(cookbook);
                break;
            }
        }
示例#2
0
        public static bool MainMenu(Cookbook cookbook)
        {
            Console.Clear();
            Console.WriteLine("VYBER, UVAŘ & BE HAPPY\n\n");
            Console.WriteLine("HLAVNÍ MENU:\n");
            Console.WriteLine("1) Zobrazit recepty");
            Console.WriteLine("2) Přidat recept");
            Console.WriteLine("3) Smazat recept");
            Console.WriteLine("4) Vygenerovat náhodný jídelníček");
            Console.WriteLine("5) Ukázat nákupní seznam");
            Console.WriteLine("6) Konec");

            switch (AuxiliaryMethod.LoadNumberInRange("\nCo chcete udělat? ", 6))
            {
            case 1:
                MenuRecipesToView(cookbook);
                Console.WriteLine("Pro navrácení do hlavního menu stiskněte jakoukoli klávesu");
                Console.ReadKey();
                return(true);

            case 2:
                CookbookConsoleUtility.AddRecipeToCookbook(cookbook);
                return(true);

            case 3:
                ShowRecipeNames(cookbook.Recipes);
                CookbookConsoleUtility.RemoveRecipeFromCookbook(cookbook);
                Console.WriteLine("Pro navrácení do hlavního menu stiskněte jakoukoli klávesu");
                Console.ReadKey();
                return(true);

            case 4:
                CookbookConsoleUtility.ShowRandomMenu(cookbook);
                Console.WriteLine("Pro navrácení do hlavního menu stiskněte jakoukoli klávesu");
                Console.ReadKey();
                return(true);

            case 5:
                ShoppingListConsoleUtility.ViewShoppingList(cookbook);
                Console.WriteLine("Pro navrácení do hlavního menu stiskněte jakoukoli klávesu");
                Console.ReadKey();
                return(true);

            case 6:
                return(false);

            default:
                return(true);
            }
        }
示例#3
0
        public static List <Ingredient> CreateListOfIngredients()
        {
            List <Ingredient> ingredients = new List <Ingredient>();
            string            userInput   = "";

            while (userInput != "n")
            {
                string name     = AuxiliaryMethod.LoadStringFromConsole("Zadejte název ingredience: ").ToLower();
                double quantity = AuxiliaryMethod.LoadNumberFromConsole("Zadejte množství: ");
                string unit     = AuxiliaryMethod.LoadStringFromConsole("Zadejte jednotku: ");
                ingredients.Add(new Ingredient(name, quantity, unit));
                userInput = AuxiliaryMethod.EnterYesOrNo("Chcete přidat další ingredienci? a/n");
            }
            return(ingredients);
        }
示例#4
0
 public static void PutRecipesToJson(Cookbook cookbook, string sourceDirectory, string filePath)
 {
     AuxiliaryMethod.CreateDirectory(sourceDirectory);
     if (cookbook.Recipes.Any() || File.Exists(filePath))
     {
         using (StreamWriter file = File.CreateText(filePath))
         {
             JsonSerializer serializer = new JsonSerializer
             {
                 Formatting = Formatting.Indented
             };
             serializer.Serialize(file, cookbook.Recipes);
         }
     }
 }
示例#5
0
 private static void ShowCertainRecipeFromList(Cookbook cookbook, List <Recipe> recipes)
 {
     ShowRecipeNames(recipes);
     if (recipes.Count > 0)
     {
         int    recipeNumber = AuxiliaryMethod.LoadNumberInRange("\nKterý recept chcete zobrazit?", recipes.Count);
         Recipe recipe       = cookbook.FindRecipeByName(cookbook.Recipes[recipeNumber - 1].Name);
         if (recipe != null)
         {
             RecipeConsoleUtility.ViewRecipe(recipe);
         }
     }
     else
     {
         Console.WriteLine("Nejsou žádné recepty k zobrazení.");
     }
 }
示例#6
0
 public static void RemoveRecipeFromCookbook(Cookbook cookbook)
 {
     if (cookbook.Recipes.Any())
     {
         int    recipeNumber = AuxiliaryMethod.LoadNumberInRange("\nKterý recept chcete smazat?", cookbook.Recipes.Count);
         Recipe recipe       = FindRecipeByNameInCookbook(cookbook, cookbook.Recipes[recipeNumber - 1].Name);
         if (recipe != null)
         {
             cookbook.DeleteRecipe(recipe);
             Console.WriteLine("Recept byl odebrán.");
         }
     }
     else
     {
         Console.WriteLine("Nejsou žádné recepty, které by mohly být smazány.");
     }
 }
示例#7
0
        public static void AddIngredientsToShoppingList(Dictionary <Category, Recipe> randomMenu, Cookbook cookbook)
        {
            if (randomMenu.Any())
            {
                string userInput = AuxiliaryMethod.EnterYesOrNo("Chcete přidat ingredience do nákupního seznamu? a/n");
                if (userInput == "a")
                {
                    int numberOfServings = (int)AuxiliaryMethod.LoadNumberFromConsole("\nPro kolik lidí budete vařit?");

                    foreach (var recipe in randomMenu.Values)
                    {
                        recipe.ConvertedIngredients = recipe.ConvertToTheNumberOfServings(numberOfServings);
                        cookbook.ShoppingList.AddIngredientsToShoppingList(recipe);
                        recipe.ConvertedIngredients.Clear();
                    }
                }
            }
        }
示例#8
0
        public static void AddRecipeToCookbook(Cookbook cookbook)
        {
            string endOfEntry = "";

            while (endOfEntry != "n")
            {
                string name = AuxiliaryMethod.LoadStringFromConsole("\nZadejte název receptu:");;
                while (cookbook.Recipes.Any(p => p.Name.ToLower() == name.ToLower()))
                {
                    Console.WriteLine("Recept s tímto názvem již existuje.");
                    name = AuxiliaryMethod.LoadStringFromConsole("\nZadejte název receptu:");
                }
                List <Ingredient> ingredients = RecipeConsoleUtility.CreateListOfIngredients();
                int    numberOfServings       = (int)AuxiliaryMethod.LoadNumberFromConsole("Jaký je počet porcí?");
                string preparation            = AuxiliaryMethod.LoadStringFromConsole("Napište postup přípravy. Jednotlivé řádky můžete oddělit dvěma mezerami.");
                preparation = preparation.Replace("  ", "\n");
                List <Category> categories = SelectCategories();
                cookbook.AddRecipe(name, numberOfServings, preparation, ingredients, categories);
                endOfEntry = AuxiliaryMethod.EnterYesOrNo("Chcete zadat další recept? a/n");
            }
        }
示例#9
0
        public static List <Category> SelectCategories()
        {
            List <Category> categories = new List <Category>();
            string          userInput  = "";

            while (userInput != "n")
            {
                Menu.ShowCategories();
                int      count          = (int)Enum.GetValues(typeof(Category)).Cast <Category>().Max();
                int      categoryNumber = (int)AuxiliaryMethod.LoadNumberInRange("Do které kategorie chcete recept zařadit?\nNapište číslo:", count);
                Category category       = (Category)(int)categoryNumber;
                if (!IsInCategoryList(categories, category))
                {
                    categories.Add(category);
                }
                else
                {
                    Console.WriteLine("Tato kategorie již byla přidána.");
                }
                userInput = AuxiliaryMethod.EnterYesOrNo("Chcete přidat další kategorii? a/n");
            }
            return(categories);
        }