Esempio n. 1
0
        public static void ProceedToReturn()
        {
            Console.Clear();

            Console.BackgroundColor = titleBackColor;
            Console.ForegroundColor = titleFontColor;
            Console.WriteLine("----RETURN BOOK----");
            Console.ResetColor();

            string username = string.Empty;

            while (true)
            {
                Console.Clear();
                Console.BackgroundColor = titleBackColor;
                Console.ForegroundColor = titleFontColor;
                Console.WriteLine("|                   RETURN 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;
            }

            int chosenBookIndex = 0;

            Console.Clear();
            Console.BackgroundColor = menuBackColor;
            Console.ForegroundColor = menuFontColor;
            Console.WriteLine("|   Esc - exit   | Enter - choose| Up, Down arrows - navigate |");
            Console.BackgroundColor = titleBackColor;
            Console.ForegroundColor = titleFontColor;
            Console.WriteLine("|                         RENT BOOK                           |");
            Console.BackgroundColor = infoBackColor;
            Console.ForegroundColor = infoFontColor;
            Console.WriteLine(">User: "******">Your books: " : "You haven't rent any books yet");
            if (books.Count != 0)
            {
                OptimisedListRender(chosenBookIndex, books);
                Guid bookid = Guid.Empty;
                while (true)
                {
                    ConsoleKey key = Console.ReadKey().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;
                    }

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

                bookid = books[chosenBookIndex].Id;
                Console.Clear();
                Console.BackgroundColor = titleBackColor;
                Console.ForegroundColor = titleFontColor;
                Console.WriteLine("----RETURN BOOK----");
                Console.BackgroundColor = infoBackColor;
                Console.ForegroundColor = infoFontColor;
                Console.WriteLine(">User: "******"----RETURN BOOK----");
                    Console.ResetColor();
                    Console.WriteLine("\n" + "No such book" + "\n" + "\n" + "Press any key to proceed...");
                    while (true)
                    {
                        if (Console.ReadKey() != null)
                        {
                            break;
                        }
                    }

                    return;
                }

                Console.BackgroundColor = infoBackColor;
                Console.ForegroundColor = infoFontColor;
                Console.WriteLine(">Book: " + b.Name);
                Console.ResetColor();
                Console.WriteLine(rental.TryReturnBook(b, user) ? "Returned successfully" : "Error, coludn't return");
            }

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