public async Task <ActionResult <object> > GeneratePlanner(GeneratePlannerInput reqBody) { string userId = ParseUserId.GetUserId(Request.Headers); /* the client will select a list of mealtypes that they want in their planner */ List <string> mealTypes = reqBody.input.mealTypes.ToList(); List <Recipe> allRecipes = (from recipe in _context.Recipes where recipe.Owner == userId where mealTypes.Contains(recipe.MealType) select recipe).ToList(); // this will shuffle the recipes List <Recipe> shuffledRecipes = allRecipes.OrderBy(r => Guid.NewGuid()).ToList(); DateTime startDate = DateTime.Parse(reqBody.input._gte); DateTime endDate = DateTime.Parse(reqBody.input._lte).AddDays(-1); /* delete existing planners for the given time because we are over writing it */ _context.RemoveRange( _context.Planners .Where(p => DateTime.Compare(p.Date, startDate) > 0) .Where(p => DateTime.Compare(p.Date, endDate) < 0) ); List <Planner> newPlanners = BuildPlannerForTheWeek( mealTypes, shuffledRecipes, userId, startDate ); await _context.Planners.AddRangeAsync(newPlanners); await _context.SaveChangesAsync(); var returningIds = newPlanners.Select(p => new { id = p.RecipeId }).ToList(); return(Ok(returningIds)); }