Ejemplo n.º 1
0
        public static void DivideDrinkListIntoPages(List <Drink> contemporaryList)
        {
            int page    = 0;
            int index   = 0;
            int counter = 0;

            while (index < contemporaryList.Count)
            {
                counter++;
                if (counter % 10 == 0)
                {
                    page    = MoveThroughPagesOrCheckDrinkInfo(contemporaryList, page);
                    counter = 0;
                }
                else
                {
                    SearchDrinkConsoleUi.PrintDrinksOnPage(contemporaryList, counter, index);
                }
                index = counter + page * 9;
                if (index == contemporaryList.Count)
                {
                    page    = MoveThroughPagesOrCheckDrinkInfo(contemporaryList, page);
                    counter = 0;
                    index   = counter + page * 9;
                }
                if (page < 0)
                {
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        public static int MoveThroughPagesOrCheckDrinkInfo(List <Drink> contemporaryList, int page)
        {
            do
            {
                SearchDrinkConsoleUi.PrintInstructionWhileOnPagedList(contemporaryList, page);
                var choice = Console.ReadKey();
                Console.Clear();
                // Moves to drink info if user press 1 - 9
                if (char.IsDigit(choice.KeyChar))
                {
                    if (choice.KeyChar != '0')
                    {
                        // select the drink form the list
                        var drink = contemporaryList[page * 9 + int.Parse(choice.KeyChar.ToString()) - 1];
                        Console.WriteLine();

                        if (TryToWriteDrinkInfo(drink) == false)
                        {
                            return(-1);
                        }
                        SearchDrinkConsoleUi.DisplayProductDetailsOptions(drink);
                        SearchDrinkConsoleUi.ReWriteDrinkListOnConsole(contemporaryList, page, choice);
                    }
                    //Cleans and rewrites list if user picked 0
                    SearchDrinkConsoleUi.ReWriteDrinkListOnConsole(contemporaryList, page, choice);
                }
                //If user picked N for Next Page, page is increased
                else if (choice.Key == ConsoleKey.N)
                {
                    if (CheckIfUserCanGoToNextPage(contemporaryList, page, choice))
                    {
                        page++;
                        return(page);
                    }
                }
                //If user picked P for Previous Page, page is decreased
                else if (choice.Key == ConsoleKey.P)
                {
                    if (CheckIfUserCanGoBackToPreviousPage(contemporaryList, page, choice))
                    {
                        page--;
                        return(page);
                    }
                }
                //Exits to main menu
                else if (choice.Key == ConsoleKey.Escape)
                {
                    return(-1);
                }
                //Rewrites drink list to console if user gives unsupported input
                else
                {
                    SearchDrinkConsoleUi.ReWriteDrinkListOnConsole(contemporaryList, page, choice);
                }
            }while (true);
        }
Ejemplo n.º 3
0
 public static bool CheckIfUserCanGoBackToPreviousPage(List <Drink> contemporaryList, int page, ConsoleKeyInfo choice)
 {
     if (page == 0)
     {
         SearchDrinkConsoleUi.ReWriteDrinkListOnConsole(contemporaryList, page, choice);
         SearchDrinkConsoleUi.TellUserThatHeCanNotGoBack(contemporaryList, page);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 4
0
 public static bool CheckIfUserCanGoToNextPage(List <Drink> contemporaryList, int page, ConsoleKeyInfo choice)
 {
     if (page * 9 + 9 > contemporaryList.Count)
     {
         SearchDrinkConsoleUi.ReWriteDrinkListOnConsole(contemporaryList, page, choice);
         SearchDrinkConsoleUi.TellUserThatHeCanNotGoToNextPage(page);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 5
0
        private static void Main()
        {
            // initial loading drinks list from file
            var loader           = new DrinkLoader();
            var drinksListGlobal = loader.InitializeDrinksFromFile();

            var exitProgram = false;

            do
            {
                var menu = new Menu();
                menu.Show();
                var choice = menu.GetUserChoice();

                switch (choice)
                {
                case MenuChoice.FindByName:
                    SearchDrinkConsoleUi.StartSearch(drinksListGlobal, SearchCriterion.Name);
                    break;

                case MenuChoice.FindByAlcoholContent:
                    SearchDrinkConsoleUi.HandleSearchDrinksByContentInConsole(drinksListGlobal);
                    break;

                case MenuChoice.FindByIngredient:
                    SearchDrinkConsoleUi.StartSearch(drinksListGlobal, SearchCriterion.Ingredients);
                    break;

                case MenuChoice.ShowReviewedDrinksList:
                    SearchDrinkConsoleUi.ShowReviewedDrinksHandler(drinksListGlobal);
                    break;

                case MenuChoice.AddCustomDrink:
                    SearchDrinkConsoleUi.StartCustomDrinkCreation(drinksListGlobal);
                    break;

                case MenuChoice.UpdateDrinksFromFile:
                    SearchDrinkConsoleUi.AddMoreDrinksFromFile(drinksListGlobal);
                    break;

                case MenuChoice.DisplayFavourites:
                    FavouritesService.Display();
                    break;

                case MenuChoice.Exit:
                    exitProgram = true;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            } while (exitProgram == false);
        }
Ejemplo n.º 6
0
 public static bool TryToWriteDrinkInfo(Drink drink)
 {
     try
     {
         SearchDrinkConsoleUi.WriteDrinkInfo(drink);
     }
     catch (ArgumentOutOfRangeException)
     {
         SearchDrinkConsoleUi.WriteExceptionCaughtInfo();
         return(false);
     }
     return(true);
 }