Beispiel #1
0
        // редактирование
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            // если ни одного объекта не выделено, выходим
            if (phonesList.SelectedItem == null)
            {
                return;
            }
            // получаем выделенный объект
            Phone phone = phonesList.SelectedItem as Phone;

            PhoneWindow phoneWindow = new PhoneWindow(new Phone
            {
                Id      = phone.Id,
                Company = phone.Company,
                Price   = phone.Price,
                Title   = phone.Title
            });

            if (phoneWindow.ShowDialog() == true)
            {
                // получаем измененный объект
                phone = db.Phones.Find(phoneWindow.Phone.Id);
                if (phone != null)
                {
                    phone.Company         = phoneWindow.Phone.Company;
                    phone.Title           = phoneWindow.Phone.Title;
                    phone.Price           = phoneWindow.Phone.Price;
                    db.Entry(phone).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
Beispiel #2
0
        // добавление
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            PhoneWindow phoneWindow = new PhoneWindow(new Phone());

            if (phoneWindow.ShowDialog() == true)
            {
                Phone phone = phoneWindow.Phone;
                db.Phones.Add(phone);
                db.SaveChanges();
            }
        }
Beispiel #3
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            PhoneWindow phoneWindow = new PhoneWindow(new Catalog());

            if (phoneWindow.ShowDialog() == true)
            {
                Catalog catalog = phoneWindow.Catalog;
                db.Catalogs.Add(catalog);
                db.SaveChanges();
                // }
            }
        }