private void Button_Click_3(object sender, RoutedEventArgs e) { /// product id = 4 kolesiki id Product product = dataBaseAC.Products.Where(q => q.Id == 4).FirstOrDefault(); MainProductEditor mainProductEditor = new MainProductEditor(dataBaseAC, new Product { Id = product.Id, Name = product.Name, Price = product.Price, Count = product.Count, Reference_id = product.Reference_id }); if (mainProductEditor.ShowDialog() == true) { // получаем измененный объект product = dataBaseAC.Products.Find(mainProductEditor.Product.Id); if (product != null) { product.Name = mainProductEditor.Product.Name; product.Price = mainProductEditor.Product.Price; product.Count = mainProductEditor.Product.Count; dataBaseAC.Entry(product).State = EntityState.Modified; dataBaseAC.SaveChanges(); } } GetDbToDataGrid(); }
private void editNotStdLesa_Click(object sender, RoutedEventArgs e) { /// product id = 6 no standart lesa id Product product = dataBaseAC.Products.Where(q => q.Id == 6).FirstOrDefault(); MainProductEditor mainProductEditor = new MainProductEditor(dataBaseAC, new Product { Id = product.Id, Name = product.Name, Price = product.Price, Count = product.Count, Reference_id = product.Reference_id }); if (mainProductEditor.ShowDialog() == true) { // получаем измененный объект product = dataBaseAC.Products.Find(mainProductEditor.Product.Id); if (product != null) { product.Name = mainProductEditor.Product.Name; product.Price = mainProductEditor.Product.Price; product.Count = mainProductEditor.Product.Count; dataBaseAC.Entry(product).State = EntityState.Modified; dataBaseAC.SaveChanges(); } for (int i = 0; i < mainProductEditor.SubProducts.Count; i++) { product = dataBaseAC.Products.Find(mainProductEditor.SubProducts[i].Id); if (product != null) { product.Name = mainProductEditor.SubProducts[i].Name; product.Price = mainProductEditor.SubProducts[i].Price; product.Count = mainProductEditor.SubProducts[i].Count; dataBaseAC.Entry(product).State = EntityState.Modified; dataBaseAC.SaveChanges(); } } } GetDbToDataGrid(); }