private void btnAdd_Click(object sender, EventArgs e) { using (FrmContactEditor frm = new FrmContactEditor(new ProductContact())) { if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (Repository.Sql.ProductContacts.Insert(frm.Contact, this.product)) { this.product.ProductContacts.Add(frm.Contact); } } } }
private void btnEdit_Click(object sender, EventArgs e) { ProductContact selected = this.dgvContacts.SelectedItem as ProductContact; if (selected == null) { throw new InvalidOperationException("Please selet a contact to edit"); } using (FrmContactEditor frm = new FrmContactEditor(selected)) { if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Repository.Sql.ProductContacts.Update(frm.Contact); } } }