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 Registration(string username, string password, string confirmPassword, User user) { sexList = SQLProcedures.GetSexes(); activityLevelList = SQLProcedures.GetActivityLevels(); diabetesTypesList = new List <int> { 1, 2 }; if (!(username.Trim() == string.Empty) && username.Length < 50) { if (!SQLProcedures.CheckExistingUsername(username)) { if (password != string.Empty && password == confirmPassword && password.Length < 50) { if (ModelState.IsValid) { int activityLevelID = SQLProcedures.GetActivityLevelID(Request.Form["ddlActivityLevel"].ToString()); SQLProcedures.InsertUser(user, activityLevelID, username, password); return(RedirectToAction("UserLogin", "UserLogin")); } else { ViewBag.ErrorMessage = "Osobni podaci nisu popunjeni!"; ViewBag.ShowError = true; ViewBag.InsertedUsername = username; FillViewBags(); return(View("Registration", user)); } } else { if (password != confirmPassword) { ViewBag.ErrorMessage = "Lozinke se ne podudaraju!"; } if (password.Length > 64) { ViewBag.ErrorMessage = "Maksimalna duljina lozinke je 50!"; } if (password == string.Empty) { ViewBag.ErrorMessage = "Lozinka nije unesena!"; } ViewBag.ShowError = true; ViewBag.InsertedUsername = username; FillViewBags(); return(View("Registration")); } } else { ViewBag.ErrorMessage = "Username već postoji!"; ViewBag.ShowError = true; ViewBag.InsertedUsername = username; FillViewBags(); return(View("Registration")); } } else { if (username.Trim() == string.Empty) { ViewBag.ErrorMessage = "Username nije unesen!"; } if (username.Length > 50) { ViewBag.ErrorMessage = "Maksimalna duljina usernamea je 50!"; } FillViewBags(); ViewBag.ShowError = true; return(View("Registration")); } }
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)); }