Beispiel #1
0
        public AwesomeModel GetMealPlanByID(AwesomeModel userModel)
        {
            userModel.MealPlan.RecipesList = new List <Recipes>();

            const string GetMealPlanByID = "Select * from mealPlans where mealPlanId = @MealPlanId;";
            const string GetMealPlanByIDWithRecipeIDs = "Select * from mealPlans_recipes where mealPlanId = @MealPlanId;";
            const string CreateRecipesFromMealPlan    = "Select * from recipes where recipeId = @recipeId;";
            Dictionary <string, object> dynamicParameterArgsMealPlan = new Dictionary <string, object>();

            dynamicParameterArgsMealPlan.Add("@MealPlanId", userModel.MealPlan.MealPlanId);

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                MealPlans results = connection.Query <MealPlans>(GetMealPlanByID, new DynamicParameters(dynamicParameterArgsMealPlan)).ToList().FirstOrDefault();
                userModel.MealPlan = results;

                List <int> resultsRecipes = connection.Query <int>(GetMealPlanByIDWithRecipeIDs, new DynamicParameters(dynamicParameterArgsMealPlan)).ToList();
                userModel.MealPlan.RecipeId = resultsRecipes;
                foreach (int recipeId in resultsRecipes)
                {
                    dynamicParameterArgsMealPlan.Add("@recipeid", recipeId);
                    Recipes recipeToAddToModel = connection.Query <Recipes>(CreateRecipesFromMealPlan, new DynamicParameters(dynamicParameterArgsMealPlan)).ToList().FirstOrDefault();
                    userModel.MealPlan.RecipesList.Add(recipeToAddToModel);
                }

                return(userModel);
            }
        }
Beispiel #2
0
        public AwesomeModel AddMealPlan(AwesomeModel newPlan)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                //newPlan.MealPlan = new MealPlans();
                newPlan.MealPlan.RecipeId = new List <int>();
                //newPlan.Recipe = new Recipes();

                connection.Open();
                Dictionary <string, object> dynamicParameterArgs = new Dictionary <string, object>();
                dynamicParameterArgs.Add("@RecipeName", newPlan.Recipe.RecipeName);
                int theRecipeId = connection.Query <int>(GetRecipeIDFromName, new DynamicParameters(dynamicParameterArgs)).ToList().FirstOrDefault();
                newPlan.MealPlan.RecipeId.Add(theRecipeId);

                Dictionary <string, object> dynamicParameterArgsMealPlan = new Dictionary <string, object>();


                dynamicParameterArgsMealPlan.Add("@MealPlanName", newPlan.MealPlan.MealPlanName);
                dynamicParameterArgsMealPlan.Add("@MealPlanImage", "https://image.flaticon.com/icons/svg/93/93104.svg");

                newPlan.MealPlan.MealPlanId = connection.Query <int>(AddMealPlanString, new DynamicParameters(dynamicParameterArgsMealPlan)).ToList().FirstOrDefault();
                foreach (int recipeId in newPlan.MealPlan.RecipeId)
                {
                    dynamicParameterArgsMealPlan.Add("@mealPlanID", newPlan.MealPlan.MealPlanId);
                    dynamicParameterArgsMealPlan.Add("@RecipeId", newPlan.MealPlan.RecipeId);
                    int affectedRows = connection.Execute(AddToMealPlanRecipes, new DynamicParameters(dynamicParameterArgsMealPlan));
                }
            }
            return(newPlan);
        }
Beispiel #3
0
        public IActionResult MealPlanDetail(int id)
        {
            AwesomeModel awesomeModel = mealPlanDAL.GetMealPlanByID(id);

            awesomeModel.Recipe = new Recipes();
            awesomeModel.Recipe.RecipeDropDown = recipeDAL.DropDownRecipeOnly();
            return(View(awesomeModel));
        }
Beispiel #4
0
 public IActionResult Submit(AwesomeModel model)
 {
     model.User = authProvider.GetCurrentUser();
     model      = mealPlanDAL.AddMealPlan(model);
     model      = mealPlanDAL.GetMealPlanByID(model.MealPlan.MealPlanId);
     return(RedirectToAction("Index"));
     //return View( "MealPlanDetail", model);
 }
Beispiel #5
0
        public IActionResult Detail(int recipeId)
        {
            AwesomeModel returnModel = new AwesomeModel();

            returnModel.Recipe      = recipeDAL.GetRecipe(recipeId);
            returnModel.Ingredients = ingredientsDAL.GetIngredientsForRecipe(recipeId);

            return(View(returnModel));
        }
Beispiel #6
0
        public IActionResult Index()
        {
            var user = authProvider.GetCurrentUser();

            //This is a way to pass a single value into your view
            ViewBag.isLoggedIn = authProvider.IsLoggedIn;
            AwesomeModel awesomeModel = recipeDAL.DropDownRecipeGet();

            awesomeModel.MealPlans = mealPlanDAL.GetMealPlans(user.UserId);
            return(View(awesomeModel));
        }
Beispiel #7
0
        public AwesomeModel DropDownRecipeGet()
        {
            AwesomeModel result = new AwesomeModel();

            result.Recipe = new Recipes();
            result.Recipe.RecipeDropDown = new List <SelectListItem>();
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                List <Recipes> DropDownRecipeList = connection.Query <Recipes>(GetAllRecipesString).ToList();

                foreach (Recipes recipe in DropDownRecipeList)
                {
                    SelectListItem choice = new SelectListItem()
                    {
                        Text = recipe.RecipeName, Value = recipe.RecipeName.ToString()
                    };
                    result.Recipe.RecipeDropDown.Add(choice);
                }
            }
            return(result);
        }
Beispiel #8
0
 public IActionResult AddRecipeToSinglePlan(int MealPlanId, AwesomeModel awesomeModel)
 {
     mealPlanDAL.AddRecipeToPlan(MealPlanId, awesomeModel.Recipe.RecipeId);
     return(RedirectToAction("MealPlanDetail", new { id = MealPlanId }));
 }