private void msp_file_add_author_Click(object sender, EventArgs e) { AuthorForm form = new AuthorForm(); try { if (DialogResult.OK == form.ShowDialog()) { authorService.AddAuthor(form.author); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void buttonEditAuthor_Click(object sender, EventArgs e) { if (dataGridViewAuthors.SelectedRows.Count > 0) { using (LibraryContext context = new LibraryContext()) { int authorID = (int)dataGridViewAuthors.SelectedRows[0].Cells["AuthorID"].Value; AuthorForm formAuthor = new AuthorForm(); formAuthor.FormAuthor = context.Authors.First(x => x.AuthorID == authorID); if (DialogResult.OK == formAuthor.ShowDialog()) { context.SaveChanges(); LoadAuthors(); } } } }
private void msp_edit_author_Click(object sender, EventArgs e) { if (null == SelectedAuthor) // Unknown state, crash application deliberately { throw new InvalidOperationException("Should not be able to click disabled controls."); } AuthorForm form = new AuthorForm(SelectedAuthor); try { if (DialogResult.OK == form.ShowDialog()) { authorService.EditAuthor(form.author); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnAddAuthor_Click(object sender, EventArgs e) { AuthorForm formAuthor = new AuthorForm(); if (DialogResult.OK == formAuthor.ShowDialog()) { using (LibraryContext context = new LibraryContext()) { Author a = new Author() { FirstName = formAuthor.FormAuthor.FirstName, LastName = formAuthor.FormAuthor.LastName, MainGenre = formAuthor.FormAuthor.MainGenre, BooksWritten = formAuthor.FormAuthor.BooksWritten, }; context.Authors.Add(a); context.SaveChanges(); LoadAuthors(); } } }