Example #1
0
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                AddRecipeDialog dialog = new AddRecipeDialog();
                if (dialog.ShowDialog() == true)
                {
                    int    newRecipeID = RecipeIDBuilder.GetRecipeID(context.Recipes);
                    Recipe r           = RecipeBuilder.BuildRecipe(dialog.titleTextBox.Text, dialog.directionTextBox.Text,
                                                                   dialog.recipeTypeListBox.SelectedValue.ToString(), newRecipeID, dialog.yeildTextBox.Text,
                                                                   dialog.servingSizeTextBox.Text, dialog.commentTextBox.Text);

                    if (string.IsNullOrWhiteSpace(r.Comment))
                    {
                        r.Comment = null;
                    }
                    if (string.IsNullOrWhiteSpace(r.ServingSize))
                    {
                        r.ServingSize = null;
                    }
                    if (string.IsNullOrWhiteSpace(r.Yield))
                    {
                        r.Yield = null;
                    }

                    context.AddNewRecipe(r);
                    recipeListBox.SelectedItem = null;
                    ClearFields();
                    context.RefreshData();
                    Recipe[] recipes = getRecipes();
                    recipeListBox.DataContext = recipes;
                }
            }
            catch (Exception ex)
            {
                var baseexception = ex.GetBaseException();
                errorLabel.Content = baseexception.Message;
            }
        }