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."); } }
public bool CheckOutBook(CheckOutLog checkOutLog) { var checkedOut = _checkOutLogSqlRepository.Add(checkOutLog); if (checkedOut != null) { return(true); } return(false); }
static void Main(string[] args) { var serviceProvider = new ServiceCollection() .AddSingleton <ILibrarianHelper, LibrarianHelper>() .AddSingleton <IBookHelper, BookHelper>() .AddTransient <IGenericSqlRepository <Librarian>, LibrarianRepository>() .AddTransient <IGenericSqlRepository <CheckOutLog>, CheckoutLogRepository>() .BuildServiceProvider(); Database.SetInitializer <LibraryContext>(new LibraryInitializer()); LibrarianRepository librarianRepository = new LibrarianRepository(); var t = librarianRepository.GetAll(); #region Check UserName and Password is true var librarianHelper = serviceProvider.GetService <ILibrarianHelper>(); var isUserLogin = librarianHelper.IsUserLogin("hoyoung", "holim1"); #endregion #region Search Book // initialize BookHelper var bookHelper = serviceProvider.GetService <IBookHelper>(); // find books search var z = bookHelper.FindBooksSearch("Andrew;Programming"); var d = bookHelper.FindBooksSearch("Science Fiction"); #endregion #region Check out book BookRepository bookRepository = new BookRepository(); var book = bookRepository.Find(5); var canUserCheckout = librarianHelper.CanCheckOut(book, 16); CheckOutLog checkOutLog = new CheckOutLog { BookID = 5, CardholderID = 10, CheckOutDate = DateTime.Now }; CheckoutLogRepository checkoutlogRepository = new CheckoutLogRepository(); if (canUserCheckout) { var checkedOut = checkoutlogRepository.Add(checkOutLog); } var found = checkoutlogRepository.GetAll().Where(x => x.BookID == checkOutLog.BookID && x.CardholderID == checkOutLog.CardholderID) .Select(x => x).ToList(); #endregion #region Update Check Out Log checkOutLog.BookID = 7; var checkOut = checkoutlogRepository.Update(checkOutLog); #endregion #region Delete Checkoutlog var foundCol = checkoutlogRepository.Find(8); checkoutlogRepository.Delete(8); foundCol = checkoutlogRepository.Find(8); #endregion }