private void Btn_checkout_Click(object sender, RoutedEventArgs e) { lbl_notFound.Visibility = Visibility.Hidden; var checkoutlogs = _checkoutLogRepository.GetAll(); var books = _bookRepository.GetAll(); var cardholders = _cardholderRepository.GetAll(); var book = books.Where(x => x.ISBN.Equals(txt_ISBN.Text)).FirstOrDefault(); var cardholder = cardholders.Where(x => x.LibraryCardID.Equals(txt_libraryCard.Text)).FirstOrDefault(); if (cardholder != null || book != null) { CheckOutLog checkOutLog = new CheckOutLog { BookID = book.BookID, CardholderID = cardholder.ID, CheckOutDate = DateTime.Now }; if (_librarianHelper.CanCheckOut(book, cardholder.ID)) { var checkedout = _checkoutLogRepository.Add(checkOutLog); SetLabel(false, "out"); } else { SetLabel(true, ""); } } else { SetLabel(true, ". ISBN or Library Card is invalid."); } }
private List <SearchDisplay> ConvertCardholderToSearchDisplay(List <Cardholder> cardholders) { List <SearchDisplay> searchDisplays = new List <SearchDisplay>(); foreach (var ch in cardholders) { var checkoutlog = _checkoutLogRepository.GetAll().Where(x => x.CardholderID == ch.ID).Select(x => x) .FirstOrDefault(); var searchDisplay = new SearchDisplay(); var hasOverDue = "No"; searchDisplay.Display = ch.ToString(); searchDisplay.Person = ch.Person; if (checkoutlog != null) { //TODO: Check if this is returning false if (_librarianHelper.CanCheckOut(checkoutlog.Book, ch.ID)) { hasOverDue = "Yes"; } searchDisplay.Display += $"Book ID: {checkoutlog.BookID}, " + $"ISBN: {checkoutlog.Book.ISBN}, " + $"Title: {checkoutlog.Book.Title}, " + $"Check Out Date: {checkoutlog.CheckOutDate.ToString("MM/dd/yyyy")}," + $"Has Over Due: {hasOverDue}"; searchDisplay.Book = checkoutlog.Book; } searchDisplays.Add(searchDisplay); } return(searchDisplays.OrderBy(x => x.Person.LastName).OrderBy(x => x.Person.FirstName).ToList()); }