Exemplo n.º 1
0
        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();
        }