diff --git a/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs b/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs index e5d2463..a474d28 100644 --- a/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs +++ b/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs @@ -58,6 +58,8 @@ namespace LoggingClient.ViewModel } private bool _LinqIsChecked; + private Customer mySelectedItem; + public bool LinqIsChecked { get { return _LinqIsChecked; } @@ -67,17 +69,26 @@ namespace LoggingClient.ViewModel OnPropertyChanged(nameof(LinqIsChecked)); } } - + public CustomerViewModel() { TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=MySQLPassword1234!;"; Customers = new List(); - + _dupChecker = new DuplicateChecker(); } - public Customer MySelectedItem { get; set; } + public Customer MySelectedItem + { + get => mySelectedItem; + set + { + mySelectedItem = value; + this.OnPropertyChanged("MySelectedItem"); + + } + } public event PropertyChangedEventHandler PropertyChanged; public string TxtConnectionString @@ -161,6 +172,8 @@ namespace LoggingClient.ViewModel { var customerModelRepositoryEF = new CustomerRepositoryEF(); Customers = customerModelRepositoryEF.GetAll(); + + this.MySelectedItem = new Customer(); } catch (Exception ex) { @@ -204,20 +217,34 @@ namespace LoggingClient.ViewModel } catch (Exception ex) { - MessageBox.Show("Error occurred: " + ex.Message); + if (MySelectedItem.kundenkonto_fk == 0) + { + MessageBox.Show("Error occurred: CustAcck ID darf nicht 0 sein"); + } + else + { + MessageBox.Show("Error occurred: " + ex.Message); + } } } if (_LinqIsChecked) { try { - //var customerModelRepositoryLinq = new CustomerRepositoryLinq(TxtConnectionString); - //customerModelRepositoryLinq.Add(NewCustomerEntry); - //Customers = customerModelRepositoryLinq.GetAll(); + var customerModelRepositoryLinq = new CustomerRepositoryLinq(); + customerModelRepositoryLinq.Add(MySelectedItem); + Customers = customerModelRepositoryLinq.GetAll(); } catch (Exception ex) { - MessageBox.Show("Error occurred: " + ex.Message); + if (MySelectedItem.kundenkonto_fk == 0) + { + MessageBox.Show("Error occurred: CustAcck ID darf nicht 0 sein"); + } + else + { + MessageBox.Show("Error occurred: " + ex.Message); + } } } if (!_EfIsChecked && !_LinqIsChecked) @@ -225,7 +252,7 @@ namespace LoggingClient.ViewModel try { var customerModelRepository = new CustomerRepository(TxtConnectionString); - customerModelRepository.Add(this.SelectedItem); + customerModelRepository.Add(MySelectedItem); this.Customers = customerModelRepository.GetAll().ToList(); } catch (Exception ex) @@ -267,7 +294,7 @@ namespace LoggingClient.ViewModel try { var customerModelRepository = new CustomerRepository(TxtConnectionString); - customerModelRepository.Delete(this.SelectedItem); + customerModelRepository.Delete(MySelectedItem); this.Customers = customerModelRepository.GetAll().ToList(); } catch (Exception ex) @@ -310,7 +337,7 @@ namespace LoggingClient.ViewModel try { var customerModelRepository = new CustomerRepository(TxtConnectionString); - customerModelRepository.Update(this.SelectedItem); + customerModelRepository.Update(MySelectedItem); this.Customers = customerModelRepository.GetAll().ToList(); } catch (Exception ex) diff --git a/LoggingClient/LoggingClient/Views/CustomerView.xaml b/LoggingClient/LoggingClient/Views/CustomerView.xaml index b09a57e..da0c89b 100644 --- a/LoggingClient/LoggingClient/Views/CustomerView.xaml +++ b/LoggingClient/LoggingClient/Views/CustomerView.xaml @@ -35,7 +35,7 @@