コード例 #1
0
        private void EditToppingButton_OnClick(object sender, RoutedEventArgs e)
        {
            Button  button = sender as Button;
            Topping copy   = new Topping(button.DataContext as Topping);
            var     dialog = new AddModifyToppingDialog(copy, _viewModel.Allergens.ToList(), _viewModel.toppingCategoryRepository.ToppingCategoryRepository.ToList());

            dialog.Owner = this;
            dialog.ShowDialog();
            if (dialog.DialogResult == true)
            {
                List <Allergen> listOfAllergens = new List <Allergen>();
                foreach (var item in dialog.ModifyTopping.BAllergens)
                {
                    if (item.IsChecked)
                    {
                        listOfAllergens.Add(new Allergen(item.Item));
                    }
                }
                copy.Allergens       = listOfAllergens;
                copy.ToppingCategory = dialog.ModifyTopping.SelectedTC;
                for (int i = 0; i < _viewModel.Toppings.Count; i++)
                {
                    if (_viewModel.Toppings[i].ToppingId == copy.ToppingId)
                    {
                        _viewModel.toppingRepository.ChangeTopping(_viewModel.Toppings[i], copy);
                        _viewModel.Toppings[i] = copy;
                    }
                }
            }
        }
コード例 #2
0
        private void AddToppingButton_OnClick(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;
            var    dialog = new AddModifyToppingDialog(null, _viewModel.Allergens.ToList(), _viewModel.toppingCategoryRepository.ToppingCategoryRepository.ToList());

            dialog.Owner = this;
            dialog.ShowDialog();
            if (dialog.DialogResult == true)
            {
                List <Allergen> listOfAllergens = new List <Allergen>();
                var             topping         = dialog.Topping;
                foreach (var item in dialog.ModifyTopping.BAllergens)
                {
                    if (item.IsChecked)
                    {
                        listOfAllergens.Add(item.Item);
                    }
                }
                topping.ToppingCategory = dialog.ModifyTopping.SelectedTC;
                topping.Allergens       = listOfAllergens;
                _viewModel.toppingRepository.AddNewTopping(topping);
                _viewModel.Toppings.Add(topping);
            }
        }