public ActionResult Details(int id = 0) { //Our keys in the UserProfile and User table are off by one //This is the solution because deleting the contents of the DB didn't help UserRepository ur = new UserRepository(); User user = ur.GetUser(id); if (user == null) { return HttpNotFound(); } return View(user); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); UserRepository ui = new UserRepository(); ui.Add(new User() { UserName = model.UserName, UserProfileId = WebSecurity.GetUserId(model.UserName), JoinDate = System.DateTime.Now }); ui.Save(); var username = model.UserName; System.Web.Security.Roles.AddUserToRole(username, "User"); return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }