public ActionResult Edit(User user) { sexList = SQLProcedures.GetSexes(); activityLevelList = SQLProcedures.GetActivityLevels(); diabetesTypesList = new List <int> { 1, 2 }; if (ModelState.IsValid) { int activityLevelID = SQLProcedures.GetActivityLevelID(Request.Form["ddlActivityLevel"].ToString()); SQLProcedures.UpdateUser(user, activityLevelID, Session["username"].ToString()); return(RedirectToAction("ViewInfo", "MyProfile")); } User u = SQLProcedures.GetUser(Session["username"].ToString()); sexList = SQLProcedures.GetSexes(); ViewBag.Sexes = new SelectList(sexList, sexList.Find(s => s.Equals(user.Sex))); activityLevelList = SQLProcedures.GetActivityLevels(); ViewBag.ActivityLevels = new SelectList(activityLevelList, activityLevelList.Find(al => SQLProcedures.GetActivityLevelID(al).Equals(user.ActivityLevel))); diabetesTypesList = new List <int> { 1, 2 }; ViewBag.DiabetesTypes = new SelectList(diabetesTypesList, diabetesTypesList.Find(dt => dt.Equals(user.DiabetesType))); return(View(user)); }
public ActionResult Edit() { User user = SQLProcedures.GetUser(Session["username"].ToString()); sexList = SQLProcedures.GetSexes(); ViewBag.Sexes = new SelectList(sexList, sexList.Find(s => s.Equals(user.Sex))); activityLevelList = SQLProcedures.GetActivityLevels(); ViewBag.ActivityLevels = new SelectList(activityLevelList, activityLevelList.Find(al => SQLProcedures.GetActivityLevelID(al).Equals(user.ActivityLevel))); diabetesTypesList = new List <int> { 1, 2 }; ViewBag.DiabetesTypes = new SelectList(diabetesTypesList, diabetesTypesList.Find(dt => dt.Equals(user.DiabetesType))); return(View(user)); }
public ActionResult GenerateMenuTwo(string submitButton, string txtCombinationDate) { if (submitButton == "Generiraj novi") { return(GenerateMenuTwo()); } if (txtCombinationDate != string.Empty) { DateTime combinationDate = DateTime.Parse(txtCombinationDate); ViewBag.CombinationDate = txtCombinationDate; if (!SQLProcedures.CheckSavedMenuForDate(Session["username"].ToString(), combinationDate)) { User user = SQLProcedures.GetUser(Session["username"].ToString()); Combination combination = SQLProcedures.GetSavedCombination(int.Parse(Session["mealNumber"].ToString())); double totalKcal = CalculateTotalKcal(); int menuID = SQLProcedures.InsertMenu(user.IDUser, combination.IDCombination, combinationDate, totalKcal); List <MenuMealData> menuMealsList = (List <MenuMealData>)Session["menuMealsList"]; foreach (MenuMealData meal in menuMealsList) { SQLProcedures.InsertMealDataForMenu(menuID, meal.MealName, meal.CarbName, meal.CarbUnits, meal.FatName, meal.FatUnits, meal.ProteinName, meal.ProteinUnits); } Session["menuMealList"] = null; return(RedirectToAction("GenerateMenuOne")); } else { ViewBag.ShowError = true; ViewBag.ErrorMsg = "Jelovnik za odabrani datum već postoji!"; return(View()); } } else { ViewBag.ShowError = true; ViewBag.ErrorMessage = "Odaberite datum!"; return(View()); } }
private double CalculateTotalKcal() { double totalKcal; User user = SQLProcedures.GetUser(Session["username"].ToString()); //get user age DateTime today = DateTime.Today; var userAge = today.Year - user.DateOfBirth.Year; if (user.DateOfBirth.Date > today.AddYears(-userAge)) { userAge--; } //get user sex int genderFactor = user.Sex == "M" ? 5 : -161; //get user activity double activityFactor = 0; switch (user.ActivityLevel) { case 1: activityFactor = 1.2; break; case 2: activityFactor = 1.375; break; case 3: activityFactor = 1.5; break; } //get user diabetes type double diabetesTypeFactor = user.DiabetesType == 1 ? 0.99 : 0.98; totalKcal = ((10 * user.Weight) + (6.25 * user.Height) - (5 * userAge) + genderFactor) * activityFactor * diabetesTypeFactor; return(Math.Round(totalKcal, 2)); }
public ActionResult ViewInfo() { User user = SQLProcedures.GetUser(Session["username"].ToString()); return(View(user)); }