private async void buttonAdd_Click(object sender, EventArgs e) { using (var form = new AddContact(new Contact())) { if (form.ShowDialog() == DialogResult.OK) { try { contactBindingSource.Add(form.ContactInfo); db.Contacts.Add(form.ContactInfo); await db.SaveChangesAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private async void buttonEdit_Click(object sender, EventArgs e) { var obj = contactBindingSource.Current as Contact; if (obj != null) { using (var frm = new AddContact(obj)) { if (frm.ShowDialog() == DialogResult.OK) { try { contactBindingSource.EndEdit(); await db.SaveChangesAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }