private void BtnAdd_Click(object sender, RoutedEventArgs e) { HospitalDBEntities db = new HospitalDBEntities(); // TODO: Replace hard coded values with Text Inputs db.Doctors.Add(new Doctor() { Name = "New Doc", Specialization = "New Spec" }); db.SaveChanges(); MessageBox.Show("New Record added!"); this.dataGridDocs.ItemsSource = db.Doctors.ToList(); }
private void DeleteRecord() { HospitalDBEntities db = new HospitalDBEntities(); var r = from d in db.Doctors where d.Id == 1 select d; Doctor doctorObj = r.SingleOrDefault(); if (doctorObj != null) { db.Doctors.Remove(doctorObj); db.SaveChanges(); } else { MessageBox.Show("Doctor does not exist!"); } }
private void UpdateDoctor() { HospitalDBEntities db = new HospitalDBEntities(); var r = from d in db.Doctors where d.Id == 2 select d; Doctor doctorObj = r.SingleOrDefault(); if (doctorObj != null) { doctorObj.Name = "Updated Doctor"; db.SaveChanges(); MessageBox.Show("Record updated!"); this.ShowDoctors(); } else { MessageBox.Show("Doctor does not exist!"); } }