//Calls the repositoryClient to get a list of meals by the user in the RecipeCalendar table for the next 6 days //groups these meals by MealTime (breakfast,lunch,dinner,snack) //Loops through the different gorupings in the meal group and maps out the meal to the correct day (mealNameOne, mealNameTwo) public async Task <ActionResult> MealCalendar() { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var meals = await _repositoryClient.GetMealPlan(userId); var mealPlan = new List <MealCalendarDataRowViewModel>(); var mealGroups = meals.GroupBy(m => m.MealTime); foreach (var group in mealGroups.OrderBy(m => (MealTimeType)Enum.Parse(typeof(MealTimeType), m.Key))) { var mealType = new MealCalendarDataRowViewModel(); mealType.MealTimeType = (MealTimeType)Enum.Parse(typeof(MealTimeType), group.Key); var mealsByDay = group.ToList(); mealType.MealNameOne = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today), _recipeClient, _repositoryClient); mealType.MealNameTwo = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today.AddDays(1)), _recipeClient, _repositoryClient); mealType.MealNameThree = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today.AddDays(2)), _recipeClient, _repositoryClient); mealType.MealNameFour = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today.AddDays(3)), _recipeClient, _repositoryClient); mealType.MealNameFive = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today.AddDays(4)), _recipeClient, _repositoryClient); mealType.MealNameSix = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today.AddDays(5)), _recipeClient, _repositoryClient); mealType.MealNameSeven = await MappingHelpers.MealMapping(mealsByDay.FirstOrDefault(m => m.CookDate.Date == DateTime.Today.AddDays(6)), _recipeClient, _repositoryClient); mealPlan.Add(mealType); } return(View(mealPlan)); }