예제 #1
0
        static void Main(string[] args)
        {
            BooksService  bs = new BooksService();
            GenresService gs = new GenresService();


            int menuChoice = 0;

            do
            {
                ShowMenu();
                Console.WriteLine("Input menu choice: ");
                menuChoice = Convert.ToInt32(Console.ReadLine());

                Console.Clear();
                switch (menuChoice)
                {
                case 1:
                    //Add Book

                    Book myBook = new Book();

                    Console.WriteLine("Input book name: ");
                    myBook.Name = Console.ReadLine();
                    Console.WriteLine();
                    Console.WriteLine("Input book isbn: ");
                    myBook.Isbn = Console.ReadLine();
                    Console.WriteLine();
                    Console.WriteLine("Input book publisher: ");
                    myBook.Publisher = Console.ReadLine();
                    Console.WriteLine();
                    Console.WriteLine("Input book author: ");
                    myBook.Author = Console.ReadLine();

                    Console.WriteLine();
                    Console.WriteLine("Input book year: ");
                    myBook.Year = Convert.ToInt32(Console.ReadLine());

                    //get all the genres that i have in my db
                    Console.WriteLine();

                    foreach (var g in gs.GetGenres())
                    {
                        Console.WriteLine($"{g.Id}. {g.Name}");
                    }
                    Console.WriteLine();
                    Console.WriteLine("Select one of the Genres by inputting the number next to the name: ");
                    myBook.GenreFK = Convert.ToInt32(Console.ReadLine());

                    Console.WriteLine();


                    bs.Add(myBook);
                    Console.WriteLine("Book was added successfully");
                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();

                    break;

                case 2:
                    //Get Books
                    break;

                case 3:
                    //Get Books by Genre

                    foreach (var g in gs.GetGenres())
                    {
                        Console.WriteLine($"{g.Id}. {g.Name}");
                    }
                    Console.WriteLine();
                    Console.WriteLine("Select one of the Genres by inputting the number next to the name: ");



                    break;

                default:
                    if (menuChoice != 999)
                    {
                        Console.WriteLine("Input is not valid");
                    }
                    break;
                }
            } while (menuChoice != 999);
        }
예제 #2
0
        static void Main(string[] args)
        {
            BooksService   bs = new BooksService();
            GenresService  gs = new GenresService();
            ReviewsService rs = new ReviewsService();

            int menuChoice = 0;

            do
            {
                bool correct = true;
                do
                {
                    try
                    {
                        ShowMenu();
                        Console.WriteLine("Input menu choice: ");
                        menuChoice = Convert.ToInt32(Console.ReadLine());
                        correct    = true;
                    }
                    catch
                    {
                        correct = false;
                    }
                }while (correct == false);


                Console.Clear();
                switch (menuChoice)
                {
                case 1:
                    //Add Book

                    Book myBook = new Book();

                    Console.WriteLine("Input book name: ");
                    myBook.Name = Console.ReadLine().ToLower();
                    Console.WriteLine();
                    Console.WriteLine("Input book isbn: ");
                    myBook.Isbn = Console.ReadLine();
                    Console.WriteLine();
                    Console.WriteLine("Input book publisher: ");
                    myBook.Publisher = Console.ReadLine();
                    Console.WriteLine();
                    Console.WriteLine("Input book author: ");
                    myBook.Author = Console.ReadLine();

                    Console.WriteLine();
                    Console.WriteLine("Input book year: ");
                    myBook.Year = Convert.ToInt32(Console.ReadLine());

                    //get all the genres that i have in my db
                    Console.WriteLine();

                    foreach (var g in gs.GetGenres())
                    {
                        Console.WriteLine($"{g.Id}. {g.Name}");
                    }
                    Console.WriteLine();
                    Console.WriteLine("Select one of the Genres by inputting the number next to the name: ");
                    myBook.GenreFK = Convert.ToInt32(Console.ReadLine());

                    Console.WriteLine();



                    bs.Add(myBook);
                    Console.WriteLine("Book was added successfully");
                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();

                    break;

                case 2:
                    //Get Books
                    List <Book> listOfAllBooks = bs.GetBooks();
                    DisplayListOfBooks(listOfAllBooks);
                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();
                    break;

                case 3:
                    //Get Books by Genre

                    foreach (var g in gs.GetGenres())
                    {
                        Console.WriteLine($"{g.Id}. {g.Name}");
                    }
                    Console.WriteLine();
                    Console.WriteLine("Select one of the Genres by inputting the number next to the name: ");
                    int selectedGenre = Convert.ToInt32(Console.ReadLine());

                    //overloading
                    //static polymorphism
                    var listOfBooksFilteredByGenre = bs.GetBooks(selectedGenre);
                    DisplayListOfBooks(listOfBooksFilteredByGenre);
                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();



                    break;

                case 4:
                    var total = bs.GetTotalNoOfBooks();

                    Console.WriteLine($"The total no of books in the library db is {total}");
                    Console.WriteLine();
                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();

                    break;

                case 5:
                    Console.WriteLine("Please input the no. next to the field you want to sort books by");
                    Console.WriteLine("1. Name");
                    Console.WriteLine("2. Author");
                    Console.WriteLine("3. Year");
                    Console.WriteLine("Input 1-3: ");
                    int fieldChoice = Convert.ToInt32(Console.ReadLine());

                    var sortedList = bs.GetBooksSorted(fieldChoice);
                    DisplayListOfBooks(sortedList);

                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();

                    break;

                case 6:


                    break;

                case 7:
                    Console.WriteLine("Which book do you want to update? Input the isbn");
                    string isbn = Console.ReadLine();

                    Book myBookToEdit = new Book();

                    Console.WriteLine("Input book name: ");
                    myBookToEdit.Name = Console.ReadLine().ToLower();
                    Console.WriteLine();

                    Console.WriteLine("Input book publisher: ");
                    myBookToEdit.Publisher = Console.ReadLine();
                    Console.WriteLine();
                    Console.WriteLine("Input book author: ");
                    myBookToEdit.Author = Console.ReadLine();

                    Console.WriteLine();
                    Console.WriteLine("Input book year: ");
                    myBookToEdit.Year = Convert.ToInt32(Console.ReadLine());

                    //get all the genres that i have in my db
                    Console.WriteLine();

                    foreach (var g in gs.GetGenres())
                    {
                        Console.WriteLine($"{g.Id}. {g.Name}");
                    }
                    Console.WriteLine();
                    Console.WriteLine("Select one of the Genres by inputting the number next to the name: ");
                    myBookToEdit.GenreFK = Convert.ToInt32(Console.ReadLine());

                    Console.WriteLine();
                    bs.Update(isbn, myBookToEdit.Name, myBookToEdit.Year, myBookToEdit.Publisher, myBookToEdit.Author, myBookToEdit.GenreFK);

                    Console.WriteLine("Book details updated");
                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();

                    break;

                case 8:

                    Console.WriteLine("Author\t\tTotal");
                    foreach (AuthorBook item in bs.GetAuthorWithNoOfBooks())
                    {
                        Console.WriteLine($"{item.Author}\t\t{item.Total}");
                    }

                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();
                    break;

                case 9:

                    Console.WriteLine("Input isbn:");
                    string isbnForReview = Console.ReadLine();

                    Console.WriteLine("Input comment:");
                    string commentForReview = Console.ReadLine();

                    Console.WriteLine("Input rating:");
                    int ratingForReview = Convert.ToInt32(Console.ReadLine());

                    rs.ReviewABook(isbnForReview, commentForReview
                                   , ratingForReview);

                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();

                    break;


                case 10:

                    Console.WriteLine("Input isbn:");
                    string isbn1 = Console.ReadLine();

                    foreach (var r in rs.GetReviews(isbn1))
                    {
                    }
                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();
                    break;


                case 11:
                    Console.WriteLine("Input isbn:");
                    string isbn2 = Console.ReadLine();

                    Console.WriteLine($"Avg rating for this book is {rs.GetAverageRatingOfBook(isbn2)}");
                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();
                    break;

                case 12:

                    foreach (var item in rs.GetBooksWithNoOfReviews())
                    {
                        Console.WriteLine($"Book isbn {item.Isbn} has {item.TotalReviews} with avg rating of {item.AvgRating}");
                    }
                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();
                    break;


                default:
                    if (menuChoice != 999)
                    {
                        Console.WriteLine("Input is not valid");
                    }
                    break;
                }
            } while (menuChoice != 999);
        }
예제 #3
0
        static void Main(string[] args)
        {
            int            menuChoice = 0;
            BookService    bs         = new BookService();
            GenresService  gs         = new GenresService();
            ReviewsService rs         = new ReviewsService();

            do
            {
                showMenu();
                menuChoice = Convert.ToInt32(Console.ReadLine());
                switch (menuChoice)
                {
                case 1:
                    //Add book

                    Book myBook = new Book();

                    Console.WriteLine("Inuput book name: ");
                    myBook.Name = Console.ReadLine();
                    Console.WriteLine();

                    Console.WriteLine("Input book isbn: ");
                    myBook.Isbn = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine();

                    Console.WriteLine("Input book publisher: ");
                    myBook.Publisher = Console.ReadLine();
                    Console.WriteLine();

                    Console.WriteLine("Input book author: ");
                    myBook.Author = Console.ReadLine();
                    Console.WriteLine();

                    Console.WriteLine("Input book year: ");
                    myBook.Year = Convert.ToInt32(Console.ReadLine());

                    //get all the genres that i have in my db
                    Console.WriteLine();

                    foreach (var g in gs.GetGenres())
                    {
                        Console.WriteLine($"{g.Id}. {g.Name}");
                    }
                    Console.WriteLine();
                    Console.WriteLine("Select one of the genres by inputting the number next to the name: ");

                    myBook.GenreFK = Convert.ToInt32(Console.ReadLine());

                    bs.Add(myBook);
                    Console.WriteLine("Book was added successfully");
                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();

                    break;

                case 2:
                    //Get Books
                    var listOfAllBooks = bs.GetBooks();
                    DisplayListOfBooks(listOfAllBooks);

                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();

                    break;

                case 3:
                    //Get books by genre

                    foreach (var g in gs.GetGenres())
                    {
                        Console.WriteLine($"{g.Id}. {g.Name}");
                    }
                    Console.WriteLine();
                    Console.WriteLine("Select one of the genres by inputting the number next to the name: ");
                    int selectedGenre = Convert.ToInt32(Console.ReadLine());

                    //overloading
                    //static polymorphism          (for the below line)
                    var listOfBooksFilteredByGenre = bs.GetBooks(selectedGenre);
                    DisplayListOfBooks(listOfBooksFilteredByGenre);

                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();

                    break;

                case 4:
                    var total = bs.GetTotalNoOfBooks();
                    Console.WriteLine($"The total number of books in the library database is {total}");
                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();

                    break;

                case 5:
                    Console.WriteLine("Please input the number next to the field you want to sort the books by");
                    Console.WriteLine("1. Name");
                    Console.WriteLine("2. Author");
                    Console.WriteLine("3 Year");
                    Console.WriteLine("Input 1-3: ");
                    int fieldChoice = Convert.ToInt32(Console.ReadLine());

                    var sortedList = bs.GetBooksSorted(fieldChoice);
                    DisplayListOfBooks(sortedList);

                    Console.WriteLine("Press a key to continue...");
                    Console.ReadKey();

                    break;

                case 6:
                    Console.WriteLine("Input isbn of book to be deleted: ");
                    int bookISBN = Convert.ToInt32(Console.ReadLine());

                    bs.Delete(bookISBN);
                    Console.WriteLine("Book has been deleted");
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey();
                    break;

                case 7:
                    Console.WriteLine("Input new isbn: ");
                    int newISBN = Convert.ToInt32(Console.ReadLine());

                    Console.WriteLine("Input new name: ");
                    string newName = Console.ReadLine();

                    Console.WriteLine("Input new year: ");
                    int newYear = Convert.ToInt32(Console.ReadLine());

                    Console.WriteLine("Input new publisher: ");
                    string newPublisher = Console.ReadLine();

                    Console.WriteLine("Input new author: ");
                    string newAuthor = Console.ReadLine();

                    Console.WriteLine("Input new genre: ");
                    int newGenre = Convert.ToInt32(Console.ReadLine());

                    bs.Update(newISBN, newName, newYear, newPublisher, newAuthor, newGenre);

                    break;

                case 8:
                    Console.WriteLine("Author\t\tTotal");
                    foreach (AuthorBook item in bs.GetAuthorWithNoOfBooks())
                    {
                        Console.WriteLine($"{item.Author}\t\t{item.Total}");
                    }
                    break;

                case 9:
                    Console.WriteLine("Input isbn: ");
                    int isbnForReview = Convert.ToInt32(Console.ReadLine());

                    Console.WriteLine("Input comment: ");
                    string commentForReview = Console.ReadLine();

                    Console.WriteLine("Input rating: ");
                    int ratingForReview = Convert.ToInt32(Console.ReadLine());

                    rs.ReviewABook(isbnForReview, commentForReview, ratingForReview);

                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey();

                    break;

                case 10:
                    Console.WriteLine("Input isbn: ");
                    int isbn = Convert.ToInt32(Console.ReadLine());

                    foreach (var r in rs.GetReviews(isbn))
                    {
                    }
                    break;

                case 11:
                    Console.WriteLine("Input isbn: ");
                    int isbn1 = Convert.ToInt32(Console.ReadLine());

                    Console.WriteLine($"Avg rating for this book is {rs.GetAverageRatingOfBook(isbn1)}");

                    break;

                case 12:
                    foreach (var item in rs.GetBooksWithNoOfReviews())
                    {
                        Console.WriteLine($"Book isbn {item.Isbn} has {item.TotalReviews} with avg rating of {item.AvgRating}");
                    }

                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey();

                    break;

                default:
                    if (menuChoice != 999)
                    {
                        Console.WriteLine("Input is not valid");
                    }

                    break;
                }
            } while (menuChoice != 999);
        }