private void AddAllergenButton_OnClick(object sender, RoutedEventArgs e) { Button button = sender as Button; var dialog = new AddModifyAllergenDialog(); dialog.Owner = this; dialog.ShowDialog(); if (dialog.DialogResult == true) { var allergen = dialog.Allergen; _viewModel.allergenRepository.AddNewAllergen(allergen); _viewModel.Allergens.Add(allergen); } }
private void EditAllergenButton_OnClick(object sender, RoutedEventArgs e) { Button button = sender as Button; Allergen copy = new Allergen(button.DataContext as Allergen); var dialog = new AddModifyAllergenDialog(copy); dialog.Owner = this; dialog.ShowDialog(); if (dialog.DialogResult == true) { for (int i = 0; i < _viewModel.Allergens.Count; i++) { if (_viewModel.Allergens[i].AllergenId == copy.AllergenId) { _viewModel.allergenRepository.ChangeAllergen(_viewModel.Allergens[i], copy); _viewModel.Allergens[i] = copy; } } } }