Exemple #1
0
        /// <summary>
        /// Method will take a list of the user's meal name for a day and size and put
        /// the information into the database, and then cycle through the list of
        /// recipe names and add them to the the meal in the appropriate table. If
        /// the recipe exists with the meal and was included, it will stay with the meal.
        /// If a recipe is not included with a meal, then it should be removed, if in table.
        /// </summary>
        /// <param name="user">Name of user creating meal</param>
        /// <param name="date"> Date for meal to be created with (YYYY-MM-DD)</param>
        /// <param name="mealName">Name of meal to be created or updated</param>
        /// <param name="size">Number of people being served</param>
        /// <param name="recipeNames">List of recipes that should be in the database.
        ///                         <strong>NOTE</strong>: Be careful of spaces between recipes</param>
        /// <example> /CalendarScreen/MealNameExisting?user=tester&date=2015-11-01&
        ///               mealName=LastMinuteResort&size=5&recipeNames=Italian%20Pasta,Caesar%20Salad </example>
        /// <example> /CalendarScreen/MealNameExisting?user=tester&date=2015-11-01&
        ///               mealName=LastMinuteResort&size=5&recipeNames=Budo Budo </example>
        /// <returns></returns>
        public ActionResult MealNameExisting(string user, string date, string mealName, int size, string recipeNames)
        {
            if (user == null || date == null || mealName == null)
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            SpeedyChefDataContext scdc = new SpeedyChefDataContext();
            int?returnValue            = -1;
            int result = scdc.MealNameExists(user, date, mealName, size, ref returnValue);
            // Removes all values for the associated mealId
            int removeResult = scdc.RemoveRecipesFromMealId(returnValue.Value);

            // Debugging purposes
            // System.Diagnostics.Debug.WriteLine(recipeNames);
            if (recipeNames != null)
            {
                // Only time PutRecipeWithMeal should be called
                string[] list = recipeNames.Split(',');
                foreach (string keyword in list)
                {
                    System.Diagnostics.Debug.WriteLine(keyword);
                    int temp = PutRecipesWithMeal(returnValue.Value, keyword);
                    if (temp == -1)
                    {
                        // Debugging purposes
                        //System.Diagnostics.Debug.WriteLine("Oh god no");
                    }
                }
            }

            return(Json(returnValue, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// Method will take a list of the user's meal name for a day and size and put 
        /// the information into the database, and then cycle through the list of 
        /// recipe names and add them to the the meal in the appropriate table. If
        /// the recipe exists with the meal and was included, it will stay with the meal. 
        /// If a recipe is not included with a meal, then it should be removed, if in table.
        /// </summary>
        /// <param name="user">Name of user creating meal</param>
        /// <param name="date"> Date for meal to be created with (YYYY-MM-DD)</param>
        /// <param name="mealName">Name of meal to be created or updated</param>
        /// <param name="size">Number of people being served</param>
        /// <param name="recipeNames">List of recipes that should be in the database.
        ///                         <strong>NOTE</strong>: Be careful of spaces between recipes</param>
        /// <example> /CalendarScreen/MealNameExisting?user=tester&date=2015-11-01&
        ///               mealName=LastMinuteResort&size=5&recipeNames=Italian%20Pasta,Caesar%20Salad </example>
        /// <example> /CalendarScreen/MealNameExisting?user=tester&date=2015-11-01&
        ///               mealName=LastMinuteResort&size=5&recipeNames=Budo Budo </example>
        /// <returns></returns>
        public ActionResult MealNameExisting(string user, string date, string mealName, int size, string recipeNames)
        {
            if (user == null || date == null || mealName == null ){
                return Json(null, JsonRequestBehavior.AllowGet);
            }
            SpeedyChefDataContext scdc = new SpeedyChefDataContext();
            int? returnValue = -1;
            int result = scdc.MealNameExists(user, date, mealName, size, ref returnValue);
            // Removes all values for the associated mealId
            int removeResult = scdc.RemoveRecipesFromMealId(returnValue.Value);
            // Debugging purposes
            // System.Diagnostics.Debug.WriteLine(recipeNames);
            if (recipeNames != null)
            {
                // Only time PutRecipeWithMeal should be called
                string[] list = recipeNames.Split(',');
                foreach (string keyword in list)
                {
                    System.Diagnostics.Debug.WriteLine(keyword);
                    int temp = PutRecipesWithMeal(returnValue.Value, keyword);
                    if (temp == -1)
                    {
                        // Debugging purposes
                        //System.Diagnostics.Debug.WriteLine("Oh god no");
                    }
                }

            }

            return Json(returnValue, JsonRequestBehavior.AllowGet);
        }