public ActionResult ProfileInfo() { ProfileUpdaterViewModel profile = new ProfileUpdaterViewModel(); var userName = User.Identity.GetUserName(); var user = _context.Users.Where(x => x.UserName == userName).First(); List <string> activityLevel = new List <string>() { "No Activity (workout 0 days a week)", "Low Activity (workout 1-2 days a week)", "Moderately Activity (workout 3-4 days a week)", "High Activity (workout 5 or more days a week)" }; List <string> genders = new List <string> { "Male", "Female" }; user.ActivityList = activityLevel; user.GenderList = genders; profile.User = user; return(View(profile)); }
public ActionResult ProfileInfo(ProfileUpdaterViewModel userProfile) { var userName = User.Identity.GetUserName(); var user = _context.Users.Where(x => x.UserName == userName).First(); user.Age = userProfile.Age; user.HeightFeet = userProfile.HeightFeet; user.HeightInches = userProfile.HeightInches; user.Weight = userProfile.Weight; user.Gender = userProfile.Gender; user.GoalWeight = userProfile.GoalWeight; user.ActivityLevel = userProfile.ActivityLevel; user.LastUpdate = DateTime.Today; ProfileUpdatesModels history = new ProfileUpdatesModels(); history.UserId = user.Id; history.Age = userProfile.Age; history.Weight = userProfile.Weight; history.HeightFeet = userProfile.HeightFeet; history.HeightInches = userProfile.HeightInches; history.Gender = userProfile.Gender; history.GoalWeight = userProfile.GoalWeight; history.ActivityLevel = userProfile.ActivityLevel; history.DateOfLog = DateTime.Today; string bmiIndicator = ""; decimal Height = (decimal.Parse(userProfile.HeightFeet) * 12) + decimal.Parse(userProfile.HeightInches); decimal bmi = (decimal.Parse(userProfile.Weight)) / (Height * Height) * 703; bmi = Math.Round(bmi * 100) / 100; if (bmi < 19) { bmiIndicator = "Underweight"; } else if (bmi == 19 || bmi < 25) { bmiIndicator = "Healthy"; } else if (bmi == 25 || bmi < 30) { bmiIndicator = "Overweight"; } else if (bmi == 30 || bmi < 40) { bmiIndicator = "Obese"; } else { @bmiIndicator = "Extremely Obese"; } user.BMI = bmi.ToString(); user.BmiIndicator = bmiIndicator; _context.ProfileHistory.Add(history); _context.SaveChanges(); return(RedirectToAction("Index", "ManageAccount")); }