Пример #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);
            }
        }
Пример #2
0
        public async Task <IActionResult> OnPostCancelAsync(string id, string?startDate = null)
        {
            var action = await UserAction;

            action.Save(new MealPlanV2(id, Array.Empty <MealPlanRecipe>()));
            SetMealPlans(action, startDate, ChangeSource.AddRecipe, id);

            if (IsHTMFRequest())
            {
                var model = MealPlans.First(x => x?.Date == id);
                return(Partial("_CancelledTemplate", model));
            }

            return(Page());
        }