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; } }
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); }
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"); } }