public void Check() { Author author1 = new Author("Mihai Irimia", "*****@*****.**"); Author author2 = new Author("Bogdan Popoi", "*****@*****.**"); Author author3 = new Author("Mihai Irimia", "*****@*****.**"); var authorList = new List <Author>(); authorList.Add(author1); authorList.Add(author2); authorList.Add(author3); var bookList = new List <Book>(); Book book1 = new Book("In cautarea fericirii", 30, "Drama", authorList); bookList.Add(book1); Author author4 = new Author("Bucatariu", "*****@*****.**"); Book book2 = new Book(" Testamentul lui Abraham ", 25, "SF", authorList); book2.AddAuthor(author4); bookList.Add(book2); Library library1 = new Library("Biblioteca", bookList); library1.AddBooks(book1); library1.AddBooks(book2); //library1.Print(); //author1.Print(); book1.Print(); //foreach(var author in authorList) // { // Console.WriteLine($"\tAuthor {author.Name} has the folowing email {author.Email}"); // } //Book book1 = new Book("In cautarea fericirii",Convert.ToDecimal( 20.90), "Drama", authorList); //var bookList = new List<Book>(); //book1.AddAuthor(author1); //book1.AddAuthor(author2); //book1.AddAuthor(author3); //bookList.Add(book1); ////book1.Print(); //foreach(var book in bookList) //{ // Console.WriteLine($"\tBook {book.Name} has the folowing email {book.Price} {book.Genre} {authorList}"); //} }
static void Main(string[] args) { var library = new Library(); while (true) { Console.WriteLine("Enter author to quit enter 'q'"); Console.Write("Author First Name: "); var firstname = Console.ReadLine(); if (firstname == "q") { Console.WriteLine("Bye!"); break; } Console.Write("Author Last Name: "); var lastname = Console.ReadLine(); Console.Write("Enter number of books: "); var bookCount = int.Parse(Console.ReadLine()); var newwriter = new Writer(); newwriter.AddName(firstname, lastname); for (int i = 0; i < bookCount; i++) { Console.Write($"{i} book title: "); var bookTitle = Console.ReadLine(); var book = new Book(newwriter, bookTitle); library.AddBooks(book); } } Console.WriteLine("Serach by author first name, to exit enter 'q'"); while (true) { Console.Write("Author first name: "); var authorName = Console.ReadLine(); if (authorName == "q") { Console.WriteLine("Bye!"); break; } Console.WriteLine("Book Title: "); var titlebook = Console.ReadLine(); List <Book> books = null; if (titlebook == string.Empty) { books = library.GetBooks(authorName); } else { books = library.GetBooks(authorName, titlebook); } foreach (var book in books) { Console.WriteLine($"{books.IndexOf(book) + 1} Book Title: {book.Title}"); } } }
static void Main(string[] args) { // Create authors and books var joyce = new Author { Id = 1, Name = "James Joyce", BirthDate = new DateTime(1882, 2, 2, 0, 0, 0) }; var ulysses = new Book { Id = 1, Title = "Ulysses", PublishDate = new DateTime(1922, 2, 2, 0, 0, 0), Author = joyce, Categories = { Category.Action, Category.Fantasy } }; joyce.Books.Add(ulysses); var tolstoi = new Author { Id = 2, Name = "Lev Tolstoi", BirthDate = new DateTime(1828, 8, 28, 0, 0, 0) }; var warAndPeace = new Book { Id = 2, Title = "War and Peace", PublishDate = new DateTime(1931, 2, 3, 0, 0, 0), Author = tolstoi, Categories = { Category.Drama, Category.Romance } }; var annaKarenina = new Book { Id = 6, Title = "Anna Karenina", PublishDate = new DateTime(1931, 2, 3, 0, 0, 0), Author = tolstoi, Categories = { Category.Drama, Category.Romance } }; tolstoi.Books.Add(warAndPeace); tolstoi.Books.Add(annaKarenina); var faur = new Author { Id = 3, Name = "Daniela Faur", BirthDate = new DateTime(1982, 10, 5, 0, 0, 0) }; var natureForces1 = new Book { Id = 3, Title = "Nature Forces - vol 1", PublishDate = new DateTime(2015, 2, 15, 0, 0, 0), Author = faur, Categories = { Category.Action, Category.Fantasy, Category.Romance, Category.SF } }; var natureForces2 = new Book { Id = 4, Title = "Nature Forces - vol 2", PublishDate = new DateTime(2017, 2, 15, 0, 0, 0), Author = faur, Categories = { Category.Action, Category.Fantasy, Category.Romance, Category.SF } }; var natureForces3 = new Book { Id = 5, Title = "Nature Forces - vol 3", PublishDate = new DateTime(2019, 2, 15, 0, 0, 0), Author = faur, Categories = { Category.Action, Category.Fantasy, Category.Romance, Category.SF } }; faur.Books.Add(natureForces1); faur.Books.Add(natureForces2); faur.Books.Add(natureForces3); // Create library var library = new Library(); // 1. Add books to the collection library.AddBooks(new List <Book> { ulysses, warAndPeace, natureForces1, natureForces2, natureForces3 }); library.AddBook(annaKarenina); // 2. Remove a book from the collection library.RemoveBook(annaKarenina); //3. Retrieve the list of all books Console.WriteLine("List of all books:"); library.GetAllBooks().Display(); //4. Retrieve the list of all books published after 1980 Console.WriteLine("List of all books published after 1980:"); library.ListAllBooksAfterYear(1980).Display(); //5. Retrieve the list of all books with one of the categories: "drama" Console.WriteLine("List of all books in drama category:"); library.ListAllBooksInCategory(Category.Drama).Display(); //6. Get the names of all authors that have published at least 3 books Console.WriteLine($"All authors that have published at least 3 books: "); library.ListAuthorsWithAtLeastAGivenNumberOfBooks(3).Display(); //7. Get the names of all authors that are born before 1990 and have written at // least 2 books of category "science-fiction" Console.WriteLine("All authors born before 1990 and with at least 2 SF books:"); library.ListAuthorsBornBeforeAndWithANumberofBooksInCategory(1990, 2, Category.SF).Display(); //8.Write a method that returns an IGrouping of Books grouped by the decade they were published in. Console.WriteLine("Books grouped by the decade they were published in:"); library.ListBooksGroupedByPublishingDecade().DisplayIGrouping(); }