Ejemplo n.º 1
0
        public static void ProceedToRent()
        {
            string username = string.Empty;

            while (true)
            {
                Console.Clear();
                Console.BackgroundColor = titleBackColor;
                Console.ForegroundColor = titleFontColor;
                Console.WriteLine("----RENT BOOK----");
                Console.ResetColor();
                Console.WriteLine();
                Console.WriteLine(">Type your username");
                username = Console.ReadLine();
                if (!username.Trim().Equals(string.Empty))
                {
                    break;
                }
            }

            Reader user = rental.TryPickUserByName(username);

            if (user == null)
            {
                NoUserCase();
                return;
            }

            while (true)
            {
                Console.Clear();
                Console.BackgroundColor = menuBackColor;
                Console.ForegroundColor = menuFontColor;
                Console.WriteLine("|   Esc - exit   | Enter - choose| Alt+F - search | Up, Down arrows - navigate |");
                Console.BackgroundColor = titleBackColor;
                Console.ForegroundColor = titleFontColor;
                Console.WriteLine("|                                  RENT BOOK                                   |");
                Console.BackgroundColor = infoBackColor;
                Console.ForegroundColor = infoFontColor;
                Console.WriteLine(">User: "******">Available books: " : "No books available");
                Book   book            = null;
                int    chosenBookIndex = 0;
                string bookname        = string.Empty;
                if (books.Count != 0)
                {
                    OptimisedListRender(chosenBookIndex, books);
                    while (true)
                    {
                        ConsoleKeyInfo keyInfo = Console.ReadKey();
                        ConsoleKey     key     = keyInfo.Key;
                        if (key == ConsoleKey.UpArrow)
                        {
                            if (chosenBookIndex > 0)
                            {
                                chosenBookIndex--;
                            }
                        }

                        if (key == ConsoleKey.DownArrow)
                        {
                            if (chosenBookIndex < books.Count - 1)
                            {
                                chosenBookIndex++;
                            }
                        }

                        if (key == ConsoleKey.Enter)
                        {
                            break;
                        }

                        if (key == ConsoleKey.Escape)
                        {
                            return;
                        }

                        if ((keyInfo.Modifiers & ConsoleModifiers.Alt) != 0 & key == ConsoleKey.F)
                        {
                            if (ProceedToFindRent(user))
                            {
                                return;
                            }
                        }

                        Console.Clear();
                        Console.BackgroundColor = menuBackColor;
                        Console.ForegroundColor = menuFontColor;
                        Console.WriteLine("|   Esc - exit   | Enter - choose| Alt+F - search | Up, Down arrows - navigate |");
                        Console.BackgroundColor = titleBackColor;
                        Console.ForegroundColor = titleFontColor;
                        Console.WriteLine("|                                  RENT BOOK                                   |");
                        Console.BackgroundColor = infoBackColor;
                        Console.ForegroundColor = infoFontColor;
                        Console.WriteLine(">User: "******">Available books: " : "No books available");
                        OptimisedListRender(chosenBookIndex, books);
                    }

                    book = books[chosenBookIndex];
                    if (book != null)
                    {
                        Console.Clear();
                        Console.BackgroundColor = titleBackColor;
                        Console.ForegroundColor = titleFontColor;
                        Console.WriteLine("----RENT BOOK----");
                        Console.BackgroundColor = infoBackColor;
                        Console.ForegroundColor = infoFontColor;
                        Console.WriteLine(">User: "******"\n" + ">Book: " + book.Name);
                        Console.ResetColor();
                        Console.WriteLine(rental.TryRentBook(book, user) ? "Rented successfully" : "Error, coludn't rent");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("No such book available");
                    }
                }
                else
                {
                    break;
                }
            }

            Console.WriteLine();
            Console.WriteLine("Press any key to proceed to menu...");
            while (true)
            {
                if (Console.ReadKey() != null)
                {
                    break;
                }
            }
        }