//Helper Methods CheckOutLogBLLCollection CreateCheckOutLogCollection() { CheckOutLogBLLCollection logs = new CheckOutLogBLLCollection(); Book book1 = new Book() { BookID = 1, Title = "Tom Goes To The Doctor" }; Book book2 = new Book() { BookID = 2, Title = "Mary Goes To The Dentist" }; CheckOutLogBLL l1 = new CheckOutLogBLL() { CheckOutLogID = 1, BookID = 1, CheckOutDate = DateTime.Now, Book = book1 }; CheckOutLogBLL l2 = new CheckOutLogBLL() { CheckOutLogID = 2, BookID = 1, CheckOutDate = DateTime.Now, Book = book1 }; CheckOutLogBLL l3 = new CheckOutLogBLL() { CheckOutLogID = 3, BookID = 2, CheckOutDate = DateTime.Now, Book = book2 }; logs.Add(l1); logs.Add(l2); logs.Add(l3); return(logs); }
private void outButton_Click(object sender, RoutedEventArgs e) { try { //First, check standing if (goodStanding) { //Check input if (checkTextBox.Text == "") { errorLabel.Content = "Please enter the ISBN of the book the patron would like to check out."; } else { BookBLL book = null; foreach (BookBLL b in books) { //Find a matching book if (b.ISBN == checkTextBox.Text) { book = b; break; } } if (book == null) { //No book was found matching the ISBN errorLabel.Content = $"No book was found matching ISBN:{checkTextBox.Text}"; } else { //A book was found, now check availability if (logs.AvailableCopies(book) > 0) { //Now we can check the book out, creating a new log CheckOutLogBLL newLog = new CheckOutLogBLL() { CardholderID = patron.ID, BookID = book.BookID, CheckOutDate = DateTime.Now }; //logs.Add(newLog); logs.AddLogToDatabase(newLog); SetListBox(); } else { //There are no more available copies of that book errorLabel.Content = $"All copies of {book.Title}: {book.ISBN} are checked out."; } } } } else { ReportStanding(); } } catch (Exception ex) { errorLabel.Content = ErrorHandler.InnermostExceptionMessage(ex); } }