private void CreateEdit(object sender, EventArgs e) { if (!CheckInputFields()) { return; } if (_loanToEdit == null) { var newLoan = new Loan { StudentId = ((Student)studentsListBox.SelectedItem).Id, BookId = ((Book)booksListBox.SelectedItem).Id, PickupDate = DateTime.Now, ReturnDeadline = DateTime.Now.AddDays(21) }; _loansRepository.Add(newLoan); } else { _loanToEdit.StudentId = ((Student)studentsListBox.SelectedItem).Id; _loanToEdit.BookId = ((Book)booksListBox.SelectedItem).Id; _loansRepository.Edit(_loanToEdit); } Close(); }
private void Return(object sender, EventArgs e) { if (_currentLoan == null) { MessageBox.Show(@"No current loan!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var fine = DateTime.Now - _currentLoan.ReturnDeadline > TimeSpan.Zero ? (DateTime.Now - _currentLoan.ReturnDeadline).Days * 0.5 : 0; var dialogResult = MessageBox.Show($@"Return delay fine: {fine}kn", @"Return", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (dialogResult != DialogResult.OK) { return; } _currentLoan.ReturnDate = DateTime.Now; _loansRepository.Edit(_currentLoan); RefreshData(); }