private async void confirmButton_Click(object sender, RoutedEventArgs e) {
            foreach (Control inputControl in _inputControls) {
                if (String.IsNullOrWhiteSpace(((TextBox)inputControl).Text)) {
                    inputControl.Focus(FocusState.Programmatic);
                    return;
                }
            }

            if (unitsComboBox.SelectedValue == null) {
                unitsComboBox.Focus(FocusState.Programmatic);
                unitsComboBox.IsDropDownOpen = true;
                return;
            }

            Ingredient ingredient = new Ingredient(titleTextBox.Text, Decimal.Parse(countTextBox.Text), (UnitOfMeasurement)unitsComboBox.SelectedValue, Decimal.Parse(priceTextBox.Text));

            // Is it an existing ingredient or new
            if (_existingIngredient == null) {
                App.DataModel.Ingredients.Add(ingredient);
            }
            else {
                _existingIngredient.Title = ingredient.Title;
                _existingIngredient.Count = ingredient.Count;
                _existingIngredient.Price = ingredient.Price;
                _existingIngredient.UnitOfMeasurement = ingredient.UnitOfMeasurement;
                _existingIngredient.CalculatePricePerUnit();

                await DataService.RecalculateProducts(ingredient);
            }

            base.GoBack();
        }
        public static async Task RecalculateProducts(Ingredient ingredient) {
            await Window.Current.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                List<Product> changedProducts = App.DataModel.Products.Where(x => x.Ingredients.Any(y => y.Ingredient.Title == ingredient.Title)).ToList();
                foreach (Product product in changedProducts) {
                    product.CalculateTotalPrice();
                    product.CalculatePricePerUnit();
                }
            });

        }
 public ProductIngredient(Ingredient ingredient, decimal ingredientCount)
 {
     this.Ingredient = ingredient;
     this.IngredientCount = ingredientCount;
 }
        protected override void OnNavigatedTo(NavigationEventArgs e) {
            base.OnNavigatedTo(e);
            if (e.Parameter == null) {
                return;
            }

            _existingIngredient = e.Parameter as Ingredient;
            if (_existingIngredient != null) {
                deleteButton.Visibility = Windows.UI.Xaml.Visibility.Visible;

                titleTextBox.Text = _existingIngredient.Title;
                countTextBox.Text = _existingIngredient.Count.ToString();
                priceTextBox.Text = _existingIngredient.Price.ToString();
                unitsComboBox.SelectedItem = _existingIngredient.UnitOfMeasurement;
            }
        }