Exemplo n.º 1
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            // если ни одного объекта не выделено, выходим
            if (ProductListDG.SelectedItem == null)
            {
                return;
            }
            // получаем выделенный объект
            Product product = ProductListDG.SelectedItem as Product;

            ProductEditor productEditor = new ProductEditor(new Product
            {
                Id           = product.Id,
                Name         = product.Name,
                Price        = product.Price,
                Count        = product.Count,
                Reference_id = product.Reference_id
            });

            if (productEditor.ShowDialog() == true)
            {
                // получаем измененный объект
                product = dataBaseAC.Products.Find(productEditor.Product.Id);
                if (product != null)
                {
                    product.Name  = productEditor.Product.Name;
                    product.Price = productEditor.Product.Price;
                    product.Count = productEditor.Product.Count;
                    dataBaseAC.Entry(product).State = EntityState.Modified;
                    dataBaseAC.SaveChanges();
                }
            }
            GetDbToDataGrid();
        }
Exemplo n.º 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ProductEditor productEditor = new ProductEditor(new Product());

            if (productEditor.ShowDialog() == true)
            {
                Product product = productEditor.Product;
                dataBaseAC.Products.Add(product);
                dataBaseAC.SaveChanges();
            }
            GetDbToDataGrid();
        }