Ejemplo n.º 1
0
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            if (phonesGrid.SelectedItem == null)
            {
                return;
            }
            Phone phone = phonesGrid.SelectedItem as Phone;

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

            if (phoneWindow.ShowDialog() == true)
            {
                phone = db.Phones.Find(phoneWindow.PhoneModel.Id);
                if (phone != null)
                {
                    phone.Category        = phoneWindow.PhoneModel.Category;
                    phone.Title           = phoneWindow.PhoneModel.Title;
                    phone.Price           = phoneWindow.PhoneModel.Price;
                    db.Entry(phone).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            //container.RegisterType<IPhone, Phone>();

            PhoneWindow phoneWindow = new PhoneWindow(new Phone());//container.Resolve<PhoneWindow>();//

            if (phoneWindow.ShowDialog() == true)
            {
                Phone phone = phoneWindow.PhoneModel;
                db.Phones.Add(phone);
                db.SaveChanges();
            }
        }