public async Task OnGetAsync() { //get info from db ApplicationUser applicationUser; string activeUserId = HttpContext.Session.GetString("activeUserId"); if (String.IsNullOrEmpty(activeUserId)) { applicationUser = await _userManager.GetUserAsync(User); HttpContext.Session.SetString("activeUserId", applicationUser.Id); HttpContext.Session.SetString("fullName", applicationUser.FullName); } else { applicationUser = await _userManager.FindByIdAsync(activeUserId); } userFullName = applicationUser.FullName; Intake = await _context.Intakes .Include(s => s.Food).Include(s => s.CustomFood).Where(s => s.User == applicationUser) .Where(s => s.Date.Date >= StartDate.Date && s.Date.Date <= StopDate.Date) .AsNoTracking() .ToListAsync(); RDIs = await _context.Rdis.ToListAsync(); if (applicationUser.GoalUnit == "Calorie") { foreach (var item in Intake) { if (item.FoodId != null) { item.Food.Enegry = applicationUser.ConvertToCalorie((int)item.Food.Enegry); } //else if (item.CustomFoodId != null) //{ // item.CustomFood.Enegry = applicationUser.ConvertToCalorie((int)item.CustomFood.Enegry); //} } SelectedGoalUnit = "Calories"; AbrevGoalUnit = "kCal"; } else { SelectedGoalUnit = "KiloJoules"; AbrevGoalUnit = "KJ"; } if (Intake.Count > 0) { //calculate intake, goals and rdi for progress bars FoodTotal = getTotalNutrients(); Goals = getGoals(applicationUser); RDI_Category = getRDICategory(applicationUser.Age, applicationUser.Gender, applicationUser.Pregnant, applicationUser.Lactating); //convert macros numbers to names of tracked nutrients string Macros = applicationUser.Macros; List <int> numbers = new List <int>(Array.ConvertAll(Macros.Split(','), int.Parse)); var goalPropertyList = Goals.GetType().GetProperties(); trackedNutrients = new String[] { goalPropertyList[numbers[0]].Name, goalPropertyList[numbers[1]].Name, goalPropertyList[numbers[2]].Name }; } }