public void changeButton_Click(object sender, EventArgs e) { if (!(dataGridView1.SelectedRows.Count > 0)) { return; } var addLibrarianForm = new AddLibrarianForm(); var librarianRepository = new LibrarianRepository(); int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } Librarian librarian = librarianRepository.FindById(id); addLibrarianForm.nameTextBox.Text = librarian.Name; addLibrarianForm.surnameTextBox.Text = librarian.Surname; addLibrarianForm.patronymicTextBox.Text = librarian.Patronymic; addLibrarianForm.dateTimePicker.Value = librarian.DateOfBirth; addLibrarianForm.telNumberTextBox.Text = librarian.TelephoneNumber; DialogResult dialogResult = addLibrarianForm.ShowDialog(this); if (dialogResult == DialogResult.Cancel) { return; } string name = addLibrarianForm.nameTextBox.Text; string surname = addLibrarianForm.surnameTextBox.Text; string patronymic = addLibrarianForm.patronymicTextBox.Text; DateTime DoB = addLibrarianForm.dateTimePicker.Value; string telNumber = addLibrarianForm.telNumberTextBox.Text; librarian.Name = name; librarian.Surname = surname; librarian.Patronymic = patronymic; librarian.DateOfBirth = DoB; librarian.TelephoneNumber = telNumber; librarianRepository.Update(librarian); _db.SaveChanges(); SetDataGridView(); }
public bool Update(Librarian librarian) { return(_librarianRepository.Update(librarian)); }