public ActionResult Index() { var users = db.Users.Include("WeightCheckIns").Where(e => (e.WeightCheckIns.Count > 0 || e.EndWeight != null) && e.StartWeight.Value >= 80 && (e.GoalWeight.Value >= 80 || e.EndWeight != null)); List<Stats> stats = new List<Stats>(); foreach (var user in users) { var stat = new Stats(user); if(stat.PoundsLost >= 0 || stat.OfficialPoundsLost >= 0) stats.Add(new Stats(user)); } ViewBag.TotalLost = Convert.ToInt32(stats.Sum(e => e.PoundsLost)); ViewBag.OfficialTotalLost = Convert.ToInt32(stats.Sum(e => e.OfficialPoundsLost)); return View(stats); }
public ActionResult Stats() { var user = db.Users.Include("WeightCheckIns").Where(e => e.UserName == HttpContext.User.Identity.Name).FirstOrDefault(); if (user.WeightCheckIns.Count > 0 && Convert.ToDecimal(user.GoalWeight) > 80) { var stats = new Stats(user); return View(stats); } else { ModelState.AddModelError("", "You need to have your Intial Weight, Goal Weight, and at least one Check In Weight entered to view Stats."); return View(); } }