public IActionResult Index(DateTime?startDate, DateTime?endDate, int?weight) { var user = authProvider.GetCurrentUser(); var userFoods = dal.GetUserFoods(user.Id); SavedDates dates = GetActiveSavedDates(startDate, endDate); TodaysWeight todaysWeight = GetTodaysWeight(weight, user); var userWeights = weightDal.GetWeights(user, dates.StartDate, dates.EndDate); var weightIsLogged = weightDal.GetTodaysWeight(user); if (!weightIsLogged) { ModelState.AddModelError("log-your-weight", "Enter today's weight"); } if (user != null) { Tuple <User, IList <UserFood>, IList <UserWeight>, TodaysWeight, bool> data = new Tuple <User, IList <UserFood>, IList <UserWeight>, TodaysWeight, bool>(user, userFoods, userWeights, todaysWeight, weightIsLogged); var weightData = new List <int>(); var dateData = new List <string>(); foreach (var item in userWeights) { weightData.Add(item.TodaysWeight); } foreach (var date in userWeights) { dateData.Add(date.DateOfEntry.ToShortDateString()); } ViewBag.AllUserWeights = weightData; ViewBag.AllUserDates = dateData; return(View(data)); } //Viewbag for chart data return(RedirectToAction("Index", "Home")); }
private TodaysWeight GetTodaysWeight(int?weight, User user) { TodaysWeight todaysWeight = HttpContext.Session.Get <TodaysWeight>(Session_Key); // See if the user has a cart in session if (todaysWeight == null) { todaysWeight = new TodaysWeight(); todaysWeight.Weight = user.CurrentWeight; HttpContext.Session.Set(Session_Key, todaysWeight); } else if (todaysWeight != null && weight != null) { todaysWeight.Weight = (int)weight; HttpContext.Session.Set(Session_Key, todaysWeight); } return(todaysWeight); }