예제 #1
0
        void EditIRecipeIngredient(object obj)
        {
            // quick validations on the Edit Recipe-Ingredient controls
            if (
                selectedRecipeIngredient != null &&
                !string.IsNullOrEmpty(selectedRecipeIngredient.ingredientName) && !string.IsNullOrWhiteSpace(selectedRecipeIngredient.ingredientName) &&
                !string.IsNullOrEmpty(selectedRecipeIngredient.measure) && !string.IsNullOrWhiteSpace(selectedRecipeIngredient.measure)
                )
            {
                var test = new CookBookData.Model.RecipeIngredient {
                    Id = selectedRecipeIngredient.Id, recipeId = selectedRecipe.Id, ingredientId = trueSelectedRecipeIngredient.Id, measureId = selectedRecipeMeasure.Id, amount = selectedRecipeIngredient.amount
                };

                if (dbActions.EditRecipeIngredient(test))
                {
                    MessageBox.Show("Recipe Ingredient updated", "Recipe Ingredient updated", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
                    // ToDo: reload the recipeIngredients listview
                    // read recipeIngredients table when recipe is selected
                    var allRecipeIngredients = dbActions.BrowseRecipeIngredients(selectedRecipe.Id);

                    ingredientItems = new ObservableCollection <RecipeIngredientItem>(
                        allRecipeIngredients.Select(obj4 =>
                    {
                        var ing = (CookBookData.RecipeIngredientItem)obj4;
                        return(new RecipeIngredientItem {
                            Id = ing.Id, ingredientName = ing.ingredientName, amount = ing.amount, measure = ing.measure
                        });
                    })
                        );
                }
            }
        }