public void AddRefreshList() { var allBooks = BookRepository.GetAllBooks(); var studentsNotToAdd = new List <Student>(); var booksNotToAdd = new List <Book>(); foreach (var student in StudentRepository.GetAllStudents()) { foreach (var allBookRent in BookRentRepository.GetAllBookRents()) { if (!allBookRent.DateOfReturn.HasValue && student.StudentId == allBookRent.StudentId) { studentsNotToAdd.Add(student); } } } foreach (var book in allBooks) { foreach (var bookRent in BookRentRepository.GetAllBookRents()) { if (!bookRent.DateOfReturn.HasValue && book.BookId == bookRent.BookId) { booksNotToAdd.Add(book); } } } var availableStudents = StudentRepository.GetAllStudents().Except(studentsNotToAdd).ToList(); var availableBooks = BookRepository.GetAllBooks().Except(booksNotToAdd).ToList(); availableBooks.ForEach(x => availableBookRentsComboBox.Items.Add(x)); availableStudents.ForEach(x => availableStudentsComboBox.Items.Add(x)); }
public void AddRefreshList() { var bookRentsOfSelectedStudents = BookRentRepository.GetAllBookRents().Where(x => x.StudentId == SelectedStudent.StudentId).ToList(); bookRentsOfSelectedStudents.ForEach(x => bookRentsListBox.Items.Add(x)); var notReturnedBookRentsOfSelectedStudent = bookRentsOfSelectedStudents.Where(x => x.DateOfReturn == null).ToList(); isRentActiveLabel.Text = notReturnedBookRentsOfSelectedStudent.Count > 0 ? "Rent active" : "Rent not active"; studentDetailsLabel.Text = SelectedStudent.Print(); }
public void AddRefreshList() { bookRentActiveListBox.Items.Clear(); booksRentNotActiveListBox.Items.Clear(); var rentedBookRents = BookRentRepository.GetAllBookRents().Where(x => x.DateOfReturn == null).ToList(); rentedBookRents.ForEach(x => bookRentActiveListBox.Items.Add(x)); var notRentedBookRents = BookRentRepository.GetAllBookRents().Where(x => x.DateOfReturn != null).ToList(); notRentedBookRents.ForEach(x => booksRentNotActiveListBox.Items.Add(x)); currentlyRentedBooksLabel.Text = $@"Current rents : {rentedBookRents.Count}"; booksToRentLabel.Text = $@"Rents from past : {notRentedBookRents.Count}"; }
private void AddButtonClick(object sender, EventArgs e) { if (availableBookRentsComboBox.SelectedItem == null || availableStudentsComboBox.SelectedItem == null) { var errorForm = new ErrorForm("You need to select student and book"); errorForm.ShowDialog(); } else { if (dateOfReturnDateTimePicker.Value < dateOfRentDateTimePicker.Value && isReturnedCheckBox.Checked) { var errorForm = new ErrorForm("Date of return cant be before date of rent"); errorForm.ShowDialog(); } else { var bookRentToAdd = new BookRent { Student = availableStudentsComboBox.SelectedItem as Student, Book = availableBookRentsComboBox.SelectedItem as Book, DateOfRent = dateOfRentDateTimePicker.Value, DateOfReturn = dateOfReturnDateTimePicker.Value }; if (!isReturnedCheckBox.Checked) { bookRentToAdd.DateOfReturn = null; } var specificBookRent = BookRentRepository.GetAllBookRents() .Where(x => x.BookId == bookRentToAdd.Book.BookId).ToList(); var specificBookRent2 = BookRentRepository.GetAllBookRents() .Where(x => x.StudentId == bookRentToAdd.Student.StudentId).ToList(); if (BookRentRepository.CheckAvailableDate(specificBookRent, bookRentToAdd) && BookRentRepository.CheckAvailableDate(specificBookRent2, bookRentToAdd)) { BookRentRepository.AddBookRent(bookRentToAdd); Close(); } else { var errorForm = new ErrorForm("That date is already taken"); errorForm.ShowDialog(); } } } }
private void SaveButtonClick(object sender, EventArgs e) { if (returnDateDateTimePicker.Value < rentDateDateTimePicker.Value && isReturnedCheckBox.Checked) { var errorForm = new ErrorForm("Date of return cant be before date of rent"); errorForm.ShowDialog(); } else { var bookRentToEdit = new BookRent { DateOfRent = rentDateDateTimePicker.Value, DateOfReturn = returnDateDateTimePicker.Value, Student = SelectedBookRent.Student, StudentId = SelectedBookRent.Student.StudentId, BookId = SelectedBookRent.Book.BookId, BookRentId = SelectedBookRent.BookRentId, Book = SelectedBookRent.Book }; if (!isReturnedCheckBox.Checked) { bookRentToEdit.DateOfReturn = null; } var specificBookRent = BookRentRepository.GetAllBookRents() .Where(x => x.BookId == bookRentToEdit.Book.BookId).ToList(); var wantedBookRent = BookRentRepository.GetAllBookRents() .Where(x => x.BookRentId == bookRentToEdit.BookRentId).ToList(); var specificBookRentFiltered = specificBookRent.Except(wantedBookRent).ToList(); var specificBookRent2 = BookRentRepository.GetAllBookRents() .Where(x => x.StudentId == bookRentToEdit.Student.StudentId).ToList(); var specificBookRent2Filtered = specificBookRent2.Except(wantedBookRent).ToList(); if (BookRentRepository.CheckAvailableDate(specificBookRentFiltered, bookRentToEdit) && BookRentRepository.CheckAvailableDate(specificBookRent2Filtered, bookRentToEdit)) { BookRentRepository.EditBookRent(bookRentToEdit); Close(); } else { var errorForm = new ErrorForm("That date is already taken"); errorForm.ShowDialog(); } } }
public void AddRefreshList() { rentedBooksListBox.Items.Clear(); notRentedListBox.Items.Clear(); var rentedBooks = BookRentRepository.GetAllBookRents().Where(x => x.DateOfReturn == null) .Select(x => x.Book).ToList(); var notRentedBooks = BookRentRepository.GetAllBookRents().Where(x => x.DateOfReturn != null) .Select(x => x.Book).ToList(); var allBooks = BookRepository.GetAllBooks(); var allBooksWithBookRentHistory = BookRentRepository.GetAllBookRents().Select(x => x.Book).ToList(); var newBooks = allBooks.Except(allBooksWithBookRentHistory); var newBooksNotRentedBooksUnion = notRentedBooks.Union(newBooks).ToList(); rentedBooks.ForEach(x => rentedBooksListBox.Items.Add(x)); newBooksNotRentedBooksUnion.ForEach(x => notRentedListBox.Items.Add(x)); rentedBooksLabel.Text = $@"Currently rented books: {rentedBooks.Count} "; notRentedBooksLabel.Text = $@"Currently available books: {newBooksNotRentedBooksUnion.Count}"; }
public void AddRefreshList() { BookRentRepository.GetAllBookRents().Where(x => x.DateOfReturn == null).Select(x => x.Book).Where(x => x.Name == SelectedBook.Name).ToList().ForEach(x => currentlyRentedBooksListBox.Items.Add(x.Print())); }
public void SetText() { bookNameLabel.Text = SelectedBook.Print(); bookCopiesLabel.Text = $@"Currently rented books of this title : {BookRentRepository.GetAllBookRents().Where(x=>x.DateOfReturn==null).Select(x => x.Book).Where(x => x.Name == SelectedBook.Name).ToList().Count}"; }