示例#1
0
 private void UpdateCar(object s, RoutedEventArgs e)
 {
     context.Update(selectedCar);
     context.SaveChanges();
     GetCars();
     ClearUpdateCarGrid();
 }
        private void AddCar(object sender, RoutedEventArgs e)
        {
            string message = CarValidator.CheckLongOfInsertedData(GetUserInput());

            if (!string.IsNullOrEmpty(message))
            {
                MessageBox.Show(message, "Error", MessageBoxButton.OK);
                return;
            }
            try
            {
                context.CarList.Add(NewCar);
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot save changes to database.", "Error", MessageBoxButton.OK);
#if DEBUG
                MessageBox.Show(ex.Message);
#endif
            }
            if (string.IsNullOrEmpty(message))
            {
                BackToMainWindow(null, null);
            }
        }