Exemple #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;
            }
        }
Exemple #2
0
        public static List <Recipe> FindRecipesByCategoryInCookbook(Cookbook cookbook, Category category)
        {
            var recipes = cookbook.FindRecipesByCategory(category);

            if (recipes.Any())
            {
                return(recipes);
            }
            Console.WriteLine($"{category}: Recept s touto kategorií v kuchařce není.");
            return(recipes);
        }
Exemple #3
0
        public static Recipe FindRecipeByNameInCookbook(Cookbook cookbook, string recipeName)
        {
            Recipe recipe = cookbook.FindRecipeByName(recipeName);

            if (recipe != null)
            {
                return(recipe);
            }
            Console.WriteLine("Recept s tímto názvem v kuchařce není.");
            return(recipe);
        }
Exemple #4
0
        public static List <Recipe> FindRecipesByIngredientInCookbook(Cookbook cookbook, string ingredientName)
        {
            List <Recipe> recipes = cookbook.FindRecipesByIngredient(ingredientName);

            if (recipes.Any())
            {
                return(recipes);
            }
            Console.WriteLine("Recept s touto ingrediencí v kuchařce není.");
            return(recipes);
        }
Exemple #5
0
        public static Cookbook LoadRecipesFromJson(string filePath)
        {
            Cookbook cookbook = new Cookbook();

            if (File.Exists(filePath))
            {
                var fileContent = File.ReadAllText(filePath);
                cookbook.Recipes = JsonConvert.DeserializeObject <List <Recipe> >(fileContent);
            }
            return(cookbook);
        }
Exemple #6
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);
            }
        }
Exemple #7
0
        static void Main()
        {
            string sourceDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Cookbook");
            string sourceFile      = Path.Combine(sourceDirectory, "recipes.json");

            Cookbook cookbook = Cookbook.LoadRecipesFromJson(sourceFile);

            while (cookbook.ShowMenu)
            {
                cookbook.ShowMenu = Menu.MainMenu(cookbook);
            }

            Cookbook.PutRecipesToJson(cookbook, sourceDirectory, sourceFile);
        }
 public static void ViewShoppingList(Cookbook cookbook)
 {
     if (cookbook.ShoppingList.IngredientsDict.Any())
     {
         int x = 1;
         foreach (var i in cookbook.ShoppingList.IngredientsDict.Values)
         {
             Console.Write($"{x++}) {i}\n");
         }
     }
     else
     {
         Console.WriteLine("Nákupní seznam je prázdný.");
     }
 }
Exemple #9
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);
         }
     }
 }
Exemple #10
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í.");
     }
 }
Exemple #11
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.");
     }
 }
Exemple #12
0
        public static void ShowRandomMenu(Cookbook cookbook)
        {
            Dictionary <Category, Recipe> randomMenu = cookbook.GenerateRandomMenu();

            foreach (Category i in Enum.GetValues(typeof(Category)))
            {
                Console.WriteLine($"{ i }:");

                if (randomMenu.ContainsKey(i))
                {
                    RecipeConsoleUtility.ViewRecipe(randomMenu[i]);
                }
                else
                {
                    Console.WriteLine("Recept s touto kategorií není k dispozici.\n");
                }
            }
            AddIngredientsToShoppingList(randomMenu, cookbook);
        }
Exemple #13
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");
            }
        }
Exemple #14
0
        public MainWindow()
        {
            Cookbook cookbook = new Cookbook();

            InitializeComponent();
        }
Exemple #15
0
 public static void ViewRecipes(Cookbook cookbook)
 {
     {
         cookbook.Recipes.ForEach(x => RecipeConsoleUtility.ViewRecipe(x));
     }
 }
Exemple #16
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();
                    }
                }
            }
        }