private void EditCustomizedProductButton_OnClick(object sender, RoutedEventArgs e) { Button button = sender as Button; CustomizedProduct copy = new CustomizedProduct(button.DataContext as CustomizedProduct); var dialog = new AddModifyCustomizedProduct(copy, _viewModel.Toppings.ToList(), _viewModel.Products.ToList()); dialog.Owner = this; dialog.ShowDialog(); if (dialog.DialogResult == true) { List <Topping> listOfToppings = new List <Topping>(); var customizeP = dialog.ModifyCustomizeProducts.CustomizedProduct; foreach (var item in dialog.ModifyCustomizeProducts.Toppings) { if (item.IsChecked) { listOfToppings.Add(item.Item); } } copy.Toppings = listOfToppings; copy.BaseProduct = dialog.ModifyCustomizeProducts.SelectedBP; for (int i = 0; i < _viewModel.CustomizedProducts.Count; i++) { if (_viewModel.CustomizedProducts[i].CustomizedProductId == copy.CustomizedProductId) { _viewModel.customizedProductRepository.ChangeCustomizedProduct(_viewModel.CustomizedProducts[i], copy); _viewModel.CustomizedProducts[i] = copy; } } } }
private void AddCustomizedProductButton_OnClick(object sender, RoutedEventArgs e) { Button button = sender as Button; var dialog = new AddModifyCustomizedProduct(null, _viewModel.Toppings.ToList(), _viewModel.Products.ToList()); dialog.Owner = this; dialog.ShowDialog(); if (dialog.DialogResult == true) { List <Topping> listOfToppings = new List <Topping>(); var customizeP = dialog.ModifyCustomizeProducts.CustomizedProduct; foreach (var item in dialog.ModifyCustomizeProducts.Toppings) { if (item.IsChecked) { listOfToppings.Add(item.Item); } } customizeP.BaseProduct = dialog.ModifyCustomizeProducts.SelectedBP; customizeP.Toppings = listOfToppings; _viewModel.customizedProductRepository.AddNewCustomizedProduct(customizeP); _viewModel.CustomizedProducts.Add(customizeP); } }