Example #1
0
 /// <summary>
 /// Delete the selected recipe from User list & Database
 /// </summary>
 /// <param name="index">index of recipe</param>
 public void Delete(int index)
 {
     if (index >= 0 && index < recipe.Count)
     {
         RecipeDAO.DeleteRecipe(recipe[index]);
         recipe.RemoveAt(index);
         recipeManager.GetCurrentUser().RemoveRecipe(index);
     }
 }
Example #2
0
        /// <summary>
        /// This will check if the input of the controls are correct. After this it will determine if the user
        /// edit an existing Recipe or is creating a new one and will add / "update" (delete and add) it to
        /// the specified database.
        /// </summary>
        /// <param name="name">Name / Title of the recipe</param>
        /// <param name="description">Description of the recipe</param>
        /// <returns>true = added the recipe to the database; false = input incorrect</returns>
        public bool AddDB(string name, string description)
        {
            if (!String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(description) && ingredients.Count > 0)
            {
                tempRecipe.title       = name;
                tempRecipe.description = description;
                tempRecipe.ingredients = ingredients;

                if (edit)
                {
                    RecipeDAO.DeleteRecipe(recipeManager.GetCurrentUser().recipes[index]);
                    tempRecipe.id = recipeManager.GetCurrentUser().recipes[index].id;
                    recipeManager.GetCurrentUser().recipes.RemoveAt(index);
                    recipeManager.GetCurrentUser().recipes.Insert(index, tempRecipe);

                    RecipeDAO.AddRecipeAsync(tempRecipe, tempRecipe.id);
                }
                else
                {
                    int result = RecipeDAO.AddRecipeAsync(tempRecipe);

                    if (result >= 0)
                    {
                        tempRecipe.id = result;
                    }

                    //Add it to running instance
                    recipeManager.GetCurrentUser().AddRecipe(tempRecipe);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }