Exemplo n.º 1
0
        // редактирование
        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();
                }
            }
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "Id,Name,Kod")] Speciality speciality)
 {
     if (ModelState.IsValid)
     {
         db.Entry(speciality).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(speciality));
 }