private void SaveExecute() { try { Ingredients = GetAllIngredients(); using (RecipeDatabaseEntities db = new RecipeDatabaseEntities()) { tblRecipe oldRecipe = new tblRecipe(); oldRecipe = db.tblRecipes.Where(r => r.RecipeID == Recipe.RecipeID).FirstOrDefault(); oldRecipe.RecipeName = Recipe.RecipeName; oldRecipe.Portions = Recipe.Portions; oldRecipe.RecipeType = Type; oldRecipe.RecipeDateOfCreation = DateTime.Now; oldRecipe.RecipeText = AllIngredientsToString(Ingredients); if (oldRecipe.RecipeText == "") { MessageBox.Show("Please choose ingredients."); return; } else { if (User.UserName == "Admin") { oldRecipe.UserID = User.UserID; } if (Ingredients != null) { foreach (tblIngredient ingredient in Ingredients) { tblRecipeIngredient recipeIngredient = new tblRecipeIngredient(); recipeIngredient.RecipeID = Recipe.RecipeID; recipeIngredient.IngredientID = ingredient.IngredientID; db.tblRecipeIngredients.Add(recipeIngredient); } } db.SaveChanges(); } } MessageBox.Show("Recipe Updated Successfully!"); updateView.Close(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
private void SaveExecute() { try { if (Recipe.IntendedFor == null) { MessageBox.Show("IntendedFor must be integer number"); return; } Recipe.DateCreated = DateTime.Now; Recipe.Author = User.PersonID; recipeService.UpdateRecipe(Recipe); view.Close(); } catch (Exception ex) { MessageBox.Show("Exception" + ex.Message.ToString()); } }