public ActionResult Register(RegisterViewModel viewModel) { DataRepository helper = new DataRepository(); List<SelectListItem> items = new List<SelectListItem>(); items.Add(new SelectListItem { Text = "Female", Value = "0" }); items.Add(new SelectListItem { Text = "Male", Value = "1" }); items.Add(new SelectListItem { Text = "Prefer not to say", Value = "2" }); viewModel.GenderOptions = items; List<SelectListItem> dobItems = new List<SelectListItem>(); int j = 0; for (int i = (int)DateTime.Now.Year; i > Convert.ToInt32(DateTime.Now.Year) - 122; i--) { dobItems.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() }); j++; } dobItems.Add(new SelectListItem { Text = "Prefer not to say", Value = j.ToString() }); viewModel.dobYearOptions = dobItems; List<SelectListItem> counties = new List<SelectListItem>(); IList<County> allCounties = helper.getCounties(); foreach (var county in allCounties) { counties.Add(new SelectListItem { Text = county.County1, Value = county.County1 }); } viewModel.countyOptions = counties; return View(viewModel); }
public User AddUser(RegisterViewModel viewModel) { User newUser = new User(); newUser.DateAdded = DateTime.Now; newUser.YearOfBirth = viewModel.dobYear; newUser.Location = viewModel.county; newUser.LastLoginDate = DateTime.Now; newUser.UserRating = 0; newUser.Username = viewModel.username; newUser.Password = viewModel.password; newUser.Alias = viewModel.username; newUser.Email = viewModel.email; newUser.Stereotype = "NULL!"; if (viewModel.gender == "1") newUser.Male = true; else if (viewModel.gender == "0") newUser.Male = false; db.Users.InsertOnSubmit(newUser); db.SubmitChanges(); return newUser; }
public ActionResult RegisterRequest(RegisterViewModel viewModel) { DataRepository helper = new DataRepository(); if (viewModel.username == null) { viewModel.errorMessage = "Please type in a username"; return RedirectToAction("Register",viewModel); } else if (viewModel.password != viewModel.retypePassword) { viewModel.errorMessage = "Make sure both passwords are the same"; return RedirectToAction("Register",viewModel); } else if (helper.usernameExists(viewModel.username)) { viewModel.errorMessage = "Sorry, that alias has been taken"; return RedirectToAction("Register",viewModel); } else { helper.AddUser(viewModel); helper.FollowSelf(viewModel.username.ToString()); Session["LoggedIn"] = "true"; Session["Username"] = viewModel.username.ToString(); return RedirectToAction("Index", "Home", new { Id = Session["Username"].ToString(), State = "Network" }); } }