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 DeleteBrand(string parameter) { try { using (Cars_DB db = new Cars_DB()) { db.BrandCar.Remove(db.BrandCar.Find(parameter)); db.SaveChanges(); MessageBox.Show("Брэнд успешно удалён"); } } catch (Exception exp) { MessageBox.Show(exp.Message); } }
private static void CreateCar(object parameter) { try { using (Cars_DB db = new Cars_DB()) { db.Cars.Add((Cars)parameter); db.SaveChanges(); MessageBox.Show("Автомобиль успешно добавлен"); } } catch (Exception exp) { MessageBox.Show(exp.Message); } }
private static void DeleteCar(string parameter) { try { using (Cars_DB db = new Cars_DB()) { db.Cars.Remove(db.Cars.Find(parameter)); 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); } }
private static void CreateBrand(object parameter) { try { using (Cars_DB db = new Cars_DB()) { BrandCar brand = (BrandCar)parameter; brand.Logotype = ViewModelService.Resolve <WorkBrandWindowViewModel>().Logotype; brand.Type_Image = ViewModelService.Resolve <WorkBrandWindowViewModel>().ImageType; db.BrandCar.Add(brand); db.SaveChanges(); MessageBox.Show("Брэнд успешно добавлен"); } } catch (Exception exp) { MessageBox.Show(exp.Message); } }