public ViewResult Index() { var id = userManager.GetUserId(User); // Get user id: var user = personRepository.getUser(id); var totalCalories = personRepository.getUserDailyCalories(id); if (!personalised) { mealRepository.AddPersonalMeals(mealPlan, totalCalories); personalised = true; } var items = mealPlan.GetMealPlanItems(); mealPlan.MealPlanItems = items; ClaimsPrincipal currentUser = this.User; var TDEE = personRepository.calculateUserTDEE(id); List <int> macros = personRepository.calculateMacros(id); int proteinPercent = (int)Math.Round((double)macros.ElementAt(0) * 4 / totalCalories * 100); int fatPercent = (int)Math.Round((double)macros.ElementAt(1) * 9 / totalCalories * 100); int carbsPercent = (int)Math.Round((double)macros.ElementAt(2) * 4 / totalCalories * 100); var mealPlanViewModel = new MealPlanViewModel() { MealPlan = mealPlan, TDEE = personRepository.calculateUserTDEE(id), TotalCalories = mealPlan.GetMealPlanTotalCalories(), DailyCalorieAmount = totalCalories, ProteinAmount = macros.ElementAt(0), FatAmount = macros.ElementAt(1), CarbsAmount = macros.ElementAt(2), ProteinPercent = proteinPercent, CarbsPercent = carbsPercent, FatPercent = fatPercent }; mealPlanViewModel.MealPlan.MealPlanItems.OrderBy(x => x.DayOfWeek); return(View(mealPlanViewModel)); }