private void Btn_checkin_Click(object sender, RoutedEventArgs e) { lbl_notFound.Visibility = Visibility.Hidden; var checkoutlogs = _checkoutLogRepository.GetAll(); var keywords = _bookHelper.SplitKeywords(txt_ISBN.Text); List <int> colIds = new List <int>(); foreach (var kw in keywords) { foreach (var cl in checkoutlogs) { try { if (cl.Book.ISBN.Equals(txt_ISBN.Text) && cl.Cardholder.LibraryCardID.Equals(txt_libraryCard.Text)) { colIds.Add(cl.CheckOutLogID); } } catch (Exception exception) { var t = _exceptionHelper.PrintAllInnerException(exception); Console.WriteLine(t); throw; } } } foreach (var colId in colIds) { _checkoutLogRepository.Delete(colId); SetLabel(false, "in"); } }
private List <Book> OverDueBooks() { List <Book> books = new List <Book>(); var checkoutlogs = _checkoutLogRepository.GetAll(); foreach (var checkoutlog in checkoutlogs) { if (DateTime.Now > checkoutlog.CheckOutDate.AddDays(30)) { books.Add(_bookRepository.Find(checkoutlog.BookID)); } } return(books); }
public int CountAvailable(Book book) { var checkout = _checkOutLogSqlRepository.GetAll().Count(x => x.BookID == book.BookID); return(book.NumberOfCopies - checkout); }
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 }