private void CloseExecute()
 {
     try
     {
         view.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception" + ex.Message.ToString());
     }
 }
 private void AddIngredientsExecute()
 {
     if (String.IsNullOrEmpty(Recipe.RecipeName) || String.IsNullOrEmpty(Recipe.Type) || String.IsNullOrEmpty(Recipe.NumberOfPersons.ToString()) ||
         Recipe.NumberOfPersons == 0 || String.IsNullOrEmpty(Recipe.Description))
     {
         MessageBox.Show("Please fill all fields.", "Notification");
     }
     else
     {
         try
         {
             recipes.CreateRecipe(Recipe, out int id);
             Recipe.RecipeId = id;
             AddIngredientsView addIngredients = new AddIngredientsView(Recipe);
             addRecipe.Close();
             addIngredients.ShowDialog();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString());
         }
     }
 }
        private void SaveExecute()
        {
            try
            {
                Ingredients                 = GetAllIngredients();
                Recipe.RecipeType           = Type;
                Recipe.RecipeDateOfCreation = DateTime.Now;
                Recipe.RecipeText           = AllIngredientsToString(Ingredients);
                if (Recipe.RecipeText == "")
                {
                    MessageBox.Show("Please choose ingredients.");
                    return;
                }
                using (RecipeDatabaseEntities db = new RecipeDatabaseEntities())
                {
                    Recipe.UserID = User.UserID;
                    db.tblRecipes.Add(Recipe);
                    db.SaveChanges();

                    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 Created Successfully!");
                addRecipe.Close();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }