private static void UpdateBrand(object parameter) { try { using (Cars_DB db = new Cars_DB()) { BrandCar brand = (BrandCar)parameter; if (brand.Brand_Name != ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name_For_Update) { db.BrandCar.Add(brand); foreach (var p in db.Cars.ToList()) { if (ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name_For_Update == p.Brand_Name) { p.Brand_Name = ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name; db.Entry(p).State = EntityState.Modified; } } db.BrandCar.Remove(db.BrandCar.Find(ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name_For_Update)); db.SaveChanges(); return; } brand.Brand_Name = ViewModelService.Resolve <WorkBrandWindowViewModel>().Brand_Name; brand.Logotype = ViewModelService.Resolve <WorkBrandWindowViewModel>().Logotype; brand.Type_Image = ViewModelService.Resolve <WorkBrandWindowViewModel>().ImageType; db.Entry(brand).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("Брэнд успешно изменён"); } } catch (Exception exp) { MessageBox.Show(exp.Message); } }
private static void UpdateCar(object parameter) { try { using (Cars_DB db = new Cars_DB()) { Cars car = (Cars)parameter; car.Car_Name = ViewModelService.Resolve <WorkCarWindowViewModel>().Car_Name; db.Entry(car).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("Автомобиль успешно изменён"); } } catch (Exception exp) { MessageBox.Show(exp.Message); } }