Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
 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();
             }
         }
     }
 }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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();
                }
            }
        }