private void btnAdd_Click(object sender, EventArgs e) { FlatForm flatForm = new FlatForm(); DialogResult result = flatForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } var flat = Flat.CreateFlat(flatForm.cbReqType.SelectedItem.ToString(), (int)flatForm.numFloor.Value, (float)flatForm.numFootage.Value, flatForm.dateBuilding.Value.Date, flatForm.elevator.Checked, (int)flatForm.cbType.SelectedValue, (int)flatForm.cbClient.SelectedValue); using (db) { db.Flats.Add(flat); db.SaveChanges(); } }