예제 #1
0
        /// <summary>
        /// Controls the user experience for the app
        /// </summary>
        public static void UserInterface()
        {
            Console.WriteLine("Welcome to Phil\'s Lending Library! Please choose an option below to get started:");
            bool quit = false;

            while (!quit)
            {
                Console.WriteLine();
                Console.WriteLine("1. View All Books");
                Console.WriteLine("2. Add a Book");
                Console.WriteLine("3. Borrow a Book");
                Console.WriteLine("4. Return a Book");
                Console.WriteLine("5. View Book Bag");
                Console.WriteLine("6. Exit");
                Console.WriteLine();

                string choice = Console.ReadLine();
                Console.WriteLine();

                switch (choice)
                {
                case "1":
                    foreach (Book novel in Library)
                    {
                        Console.WriteLine($"- {novel.Title} By: {novel.BookAuthor.FirstName} {novel.BookAuthor.LastName} -- {novel.BookGenre} genre");
                    }
                    break;

                case "2":
                    Console.WriteLine("Please enter the title of the book:");
                    string title = Console.ReadLine();
                    Console.WriteLine();
                    Console.WriteLine("Please enter the author\'s first name:");
                    string first = Console.ReadLine();
                    Console.WriteLine();
                    Console.WriteLine("Please enter the author\'s last name:");
                    string last = Console.ReadLine();
                    Console.WriteLine();
                    Console.WriteLine("Please select the genre of this book");
                    int genre = 0;
                    while (genre < 1 || genre > 6)
                    {
                        foreach (int i in Enum.GetValues(typeof(Book.Genre)))
                        {
                            Console.WriteLine($"{i}. {(Book.Genre)i}");
                        }
                        string genreAnswer = Console.ReadLine();
                        genre = Int32.TryParse(genreAnswer, out int result) ? result : 0;
                    }
                    Book book = new Book();
                    book.Title      = title;
                    book.BookAuthor = new Author(first, last);
                    book.BookGenre  = (Book.Genre)genre;
                    Library.Add(book);
                    break;

                case "3":
                    Console.WriteLine("Choose the book that you would like to borrow:");
                    int count  = 0;
                    int borrow = -1;
                    while (borrow < 0 || borrow > Library.Count())
                    {
                        count = 0;
                        foreach (Book b in Library)
                        {
                            Console.WriteLine($"{count + 1}. {b.Title} By: {b.BookAuthor.FirstName} {b.BookAuthor.LastName} -- {b.BookGenre} genre");
                            count++;
                        }
                        Console.WriteLine();
                        string answer = Console.ReadLine();
                        borrow = Int32.TryParse(answer, out int result) ? result : -1;
                    }
                    count = 0;
                    foreach (Book b in Library)
                    {
                        if (borrow == count + 1)
                        {
                            BorrowBook(b.Title);
                        }
                        count++;
                    }
                    break;

                case "4":
                    Console.WriteLine("Choose the book that you would like to return:");
                    int count2  = 0;
                    int borrow2 = -1;
                    while (borrow2 < 0 || borrow2 > BookBag.Count)
                    {
                        count2 = 0;
                        foreach (Book b in BookBag)
                        {
                            Console.WriteLine($"{count2 + 1}. {b.Title} By: {b.BookAuthor.FirstName} {b.BookAuthor.LastName} -- {b.BookGenre} genre");
                            count2++;
                        }
                        Console.WriteLine();
                        string answer = Console.ReadLine();
                        borrow2 = Int32.TryParse(answer, out int result) ? result : -1;
                    }
                    count2 = 0;
                    Book returnBook = new Book();
                    foreach (Book b in BookBag)
                    {
                        if (borrow2 == count2 + 1)
                        {
                            returnBook = b;
                        }
                        count2++;
                    }
                    ReturnBook(returnBook.Title);
                    break;

                case "5":
                    foreach (Book i in BookBag)
                    {
                        Console.WriteLine($"- {i.Title} By: {i.BookAuthor.FirstName} {i.BookAuthor.LastName} -- {i.BookGenre} genre");
                    }
                    break;

                case "6":
                    quit = true;
                    break;

                default:
                    Console.WriteLine("Invalid Selection Please Try Again");
                    break;
                }
            }
        }