private void btnContinue_Click(object sender, EventArgs e) { if (_newFacility) { FacilitiesForm.AddFacility(this.txtName.Text, this.txtAddress.Text, this.txtZip.Text, this.txtPhone.Text, this.txtCity.Text, this.lbStates.Text); } else { using (var MedDB = new MedicalEntities()) { var entry = MedDB.Facilities.Find(_facility.FacilityID); _facility.Address = this.txtAddress.Text; _facility.City = this.txtCity.Text; _facility.Name = this.txtName.Text; _facility.Phone = this.txtPhone.Text; _facility.Zip = this.txtZip.Text; _facility.State = this.lbStates.Text; MedDB.Entry(entry).CurrentValues.SetValues(_facility); MedDB.SaveChanges(); } } this.Close(); }
private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show($"Are you sure you want to delete {selection.Name} from the facilities table?", "Are You Sure?", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { MessageBox.Show($"{selection.Name} was sucessfully deleted from the facilities table!"); using (var MedDB = new MedicalEntities()) { MedDB.Entry(selection).State = EntityState.Deleted; MedDB.SaveChanges(); } UpdateFacilities(); } }