Exemplo n.º 1
0
 public BookRentsListForm(BookRentRepository bookRentRepository, StudentRepository studentRepository, BookRepository bookRepository)
 {
     InitializeComponent();
     BookRentRepository = bookRentRepository;
     StudentRepository  = studentRepository;
     BookRepository     = bookRepository;
 }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
 public BookListForm(BookRentRepository bookRentRepository, BookRepository bookRepository, AuthorRepository authorRepository, PublisherRepository publisherRepository)
 {
     InitializeComponent();
     BookRentRepository  = bookRentRepository;
     BookRepository      = bookRepository;
     AuthorRepository    = authorRepository;
     PublisherRepository = publisherRepository;
 }
 public BookRentEditForm(BookRentRepository bookRentRepository, BookRepository bookRepository, StudentRepository studentRepository)
 {
     InitializeComponent();
     BookRentRepository = bookRentRepository;
     BookRepository     = bookRepository;
     StudentRepository  = studentRepository;
     returnDateDateTimePicker.Hide();
 }
Exemplo n.º 5
0
 public MenuForm()
 {
     InitializeComponent();
     LibraryContext      = new LibraryContext();
     StudentRepository   = new StudentRepository(LibraryContext);
     BookRepository      = new BookRepository(LibraryContext);
     BookRentRepository  = new BookRentRepository(LibraryContext);
     AuthorRepository    = new AuthorRepository(LibraryContext);
     PublisherRepository = new PublisherRepository(LibraryContext);
 }
Exemplo n.º 6
0
 public BookRentCreateForm(BookRentRepository bookRentRepository, BookRepository bookRepository, StudentRepository studentRepository)
 {
     InitializeComponent();
     BookRentRepository = bookRentRepository;
     BookRepository     = bookRepository;
     StudentRepository  = studentRepository;
     dateOfReturnDateTimePicker.Hide();
     dateOfReturnDateTimePicker.MaxDate = DateTime.Now;
     dateOfReturnDateTimePicker.MinDate = DateTime.Now.AddYears(-8);
 }
        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();
        }
Exemplo n.º 8
0
        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}";
        }
Exemplo n.º 9
0
 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();
                }
            }
        }
Exemplo n.º 11
0
        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}";
        }
Exemplo n.º 12
0
        private void DeleteBookRentButtonClick(object sender, EventArgs e)
        {
            var selectedBookRent = booksRentNotActiveListBox.SelectedItem as BookRent;

            if (bookRentActiveListBox.SelectedItem != null)
            {
                selectedBookRent = bookRentActiveListBox.SelectedItem as BookRent;
            }
            if (selectedBookRent == null)
            {
                var errorForm = new ErrorForm("You need to select bookrent.");
                errorForm.ShowDialog();
            }
            else
            {
                BookRentRepository.RemoveBookRent(selectedBookRent.BookRentId);
                AddRefreshList();
            }
        }
 public StudentsDetailsForm(StudentRepository studentRepository, BookRentRepository bookRentRepository)
 {
     InitializeComponent();
     StudentRepository  = studentRepository;
     BookRentRepository = bookRentRepository;
 }
Exemplo n.º 14
0
 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()));
 }
Exemplo n.º 15
0
 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}";
 }
Exemplo n.º 16
0
 public BookDetailsForm(BookRentRepository bookRentRepository, BookRepository bookRepository)
 {
     InitializeComponent();
     BookRentRepository = bookRentRepository;
     BookRepository     = bookRepository;
 }