public static void ShowReviewedDrinksHandler(List <Drink> drinks)
        {
            var reviewService = new ReviewService();

            Console.Clear();
            PagingHandler.DivideDrinkListIntoPages(reviewService.ShowReviewed(drinks));
        }
예제 #2
0
 public static void Display()
 {
     if (Favourites.Any())
     {
         Console.WriteLine("\nYour favourite drinks:\n");
         PagingHandler.DivideDrinkListIntoPages(Favourites);
     }
     else
     {
         Console.WriteLine("\nYour favourites list is empty.\n");
         Console.WriteLine("\nPress any key to go back to the main menu.");
         Console.ReadKey();
     }
 }
        public static void StartSearch(List <Drink> drinksList, SearchCriterion searchCriterion)
        {
            bool continueSearch = true;

            do
            {
                Console.Clear();
                Console.WriteLine($"\nSearch drink by {searchCriterion}\n".ToUpper());
                Console.WriteLine("-------------------------------------------------------------------------------------------------------------------");

                List <Drink> drinksFound = null;

                switch (searchCriterion)
                {
                case SearchCriterion.Name:
                    var nameToSearch = GetTextToSearch(searchCriterion);
                    drinksFound = SearchDrink.SearchByName(nameToSearch, drinksList);
                    break;

                case SearchCriterion.Ingredients:
                    Console.WriteLine("\nInstructions: \nYou can provide ONE or MORE ingredients - separated with a space. \nYou can search drinks containing ALL or ANY of provided ingredients.");
                    Console.WriteLine("\nWould you like to display drinks containing: \n1. ALL provided ingredients \n2. ANY of provided ingredients\n(1/2) ");
                    var  searchOption = SearchDrinkOption.All;
                    bool incorrectInputIngredientsChoice;
                    do
                    {
                        var searchOptionChoice = Console.ReadKey();
                        switch (searchOptionChoice.KeyChar)
                        {
                        case '1':
                            searchOption = SearchDrinkOption.All;
                            incorrectInputIngredientsChoice = false;
                            break;

                        case '2':
                            searchOption = SearchDrinkOption.Any;
                            incorrectInputIngredientsChoice = false;
                            break;

                        default:
                            Console.WriteLine("\nPlease enter correct answer.");
                            incorrectInputIngredientsChoice = true;
                            break;
                        }
                    } while (incorrectInputIngredientsChoice);

                    var ingredientsToSearch = GetTextToSearch(searchCriterion);
                    drinksFound = SearchDrink.SearchByIngredients(new SortedSet <string>(ingredientsToSearch.Split(' ')), drinksList, searchOption);
                    break;
                }

                if (drinksFound != null && drinksFound.Count == 0)
                {
                    Console.WriteLine("\nNo drinks found in the database matching your criteria.");
                }
                else
                {
                    PagingHandler.DivideDrinkListIntoPages(drinksFound);
                }

                var incorrectInputEndSearch = true;
                do
                {
                    Console.Write($"\nContinue search by {searchCriterion.ToString().ToLower()} (yes: [y/enter] / no: [n/esc])? ");
                    var continueUserInput = Console.ReadKey();
                    if (continueUserInput.KeyChar == 'y' || continueUserInput.KeyChar == 'Y' || continueUserInput.Key == ConsoleKey.Enter)
                    {
                        incorrectInputEndSearch = false;
                    }
                    else if (continueUserInput.KeyChar == 'n' || continueUserInput.KeyChar == 'N' || continueUserInput.Key == ConsoleKey.Escape)
                    {
                        incorrectInputEndSearch = false;
                        continueSearch          = false;
                    }
                } while (incorrectInputEndSearch);
            } while (continueSearch);
        }