public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { string confirmationToken = WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { Email = model.Email }, true); dynamic email = new Email("RegEmail"); email.To = model.Email; email.UserName = model.UserName; email.ConfirmationToken = confirmationToken; email.Send(); using (var db = new ChessDatabase()) { var user = new User { ID = WebSecurity.CurrentUserId, UserName = model.UserName, PlayingRating = 1200, ProblemRating = 0, DateCreated = DateTime.Now, Email = model.Email, ConfirmationToken = confirmationToken, CultureInfo = "en", Gain = 0, Minutes = 5, RatingFrom = 0, RatingTo = 3000, IsRated = true, Comments = new List <Comment>(), Matches = new List <Match>() }; Roles.AddUserToRole(model.UserName, db.Users.Any() ? UserRoles.Player.ToString() : UserRoles.Administrator.ToString()); db.Users.Add(user); db.SaveChanges(); } return(RedirectToAction("RegisterStepTwo", "Account")); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Information(LocalPasswordModel model) { using (var db = new ChessDatabase()) { var modifiedUser = db.Users.Find(model.User.ID); if (modifiedUser == null) { return(RedirectToAction("Manage")); } modifiedUser.FirstName = model.User.FirstName; modifiedUser.LastName = model.User.LastName; modifiedUser.Address = model.User.Address; modifiedUser.UserName = model.User.UserName; db.SaveChanges(); } return(RedirectToAction("Manage")); }