//method to edit a recipe ingredient private void btnAddrecipeEditRecipeIngredient_Click(object sender, RoutedEventArgs e) { //if the user has selected a recipe ingredient from the datagrid a new window will open with the information from ingredient user wants to edit if (dgRecipeIngredients.SelectedItem != null) { //calls method get recipeIngredient to set value of recipeIngredient RecipeIngredient recipeIngredient = getRecipeIngredient(dgRecipeIngredients.SelectedItem); EditRecipeIngredients edit = new EditRecipeIngredients(recipeIngredient); edit.ShowDialog(); dgRecipeIngredients.ItemsSource = recipe.RecipeIngredients.Select(ingredient => new { ingredient.Id, ingredient.Quantity, ingredient.Measurement, Ingredient = ingredient.Ingredient.Name }); } else { MessageBox.Show("Please select a ingredient to update.", "Edit Ingredient"); } }
//this button adds a recipe ingredient to the recipe ingredient datagrid and resets the text boxes private void btnAddRecipeIngredient_Click(object sender, RoutedEventArgs e) { if (txtRecipeIngredientQuantity.Text != "" && cbRecipeIngredientMeasurement.Text != "" && txtRecipeIngredientIngredient.Text != "") { RecipeIngredient recipeIngredient = new RecipeIngredient(); recipeIngredient.Ingredient = new Ingredient() { Name = txtRecipeIngredientIngredient.Text }; recipeIngredient.Recipe = recipe; recipeIngredient.Quantity = Convert.ToDouble(txtRecipeIngredientQuantity.Text); recipeIngredient.Measurement = cbRecipeIngredientMeasurement.Text; recipe.RecipeIngredients.Add(recipeIngredient); dgRecipeIngredients.ItemsSource = recipe.RecipeIngredients.Select(ingredient => new { ingredient.Id, ingredient.Quantity, ingredient.Measurement, Ingredient = ingredient.Ingredient.Name }); txtRecipeIngredientQuantity.Text = ""; txtRecipeIngredientIngredient.Text = ""; } else { MessageBox.Show("Please fill in all ingredient fields.", "Add Ingredient"); } }
private void detach_RecipeIngredients(RecipeIngredient entity) { this.SendPropertyChanging(); entity.Recipe = null; }
partial void DeleteRecipeIngredient(RecipeIngredient instance);
partial void UpdateRecipeIngredient(RecipeIngredient instance);
partial void InsertRecipeIngredient(RecipeIngredient instance);
private void attach_RecipeIngredients(RecipeIngredient entity) { this.SendPropertyChanging(); entity.Ingredient = this; }