// редактирование private void Edit_Click(object sender, RoutedEventArgs e) { // если ни одного объекта не выделено, выходим if (specialityList.SelectedItem == null) { return; } // получаем выделенный объект Speciality speciality = specialityList.SelectedItem as Speciality; SpecialityWindow specialityWindow = new SpecialityWindow(new Speciality { IdSpeciality = speciality.IdSpeciality, Code = speciality.Code, NameSpeciality = speciality.NameSpeciality }); if (specialityWindow.ShowDialog() == true) { // Получение измененного объекта speciality = db.Specialities.Find(specialityWindow.Speciality.IdSpeciality); if (speciality != null) { speciality.Code = specialityWindow.Speciality.Code; speciality.NameSpeciality = specialityWindow.Speciality.NameSpeciality; db.Entry(speciality).State = EntityState.Modified; db.SaveChanges(); } } }
private void Add_Click(object sender, RoutedEventArgs e) { SpecialityWindow specialityWindow = new SpecialityWindow(new Speciality()); if (specialityWindow.ShowDialog() == true) { Speciality speciality = specialityWindow.Speciality; db.Specialities.Add(speciality); db.SaveChanges(); } }