public async Task<ActionResult> Register(RegisterUserViewModel userModel) { if (this.ModelState.IsValid) { var user = new User { FirstName = userModel.FirstName, LastName = userModel.LastName, UserName = userModel.UserName, Email = userModel.Email, DateOfBirth = userModel.DateOfBirth }; var result = await this.UserManager.CreateAsync(user, userModel.Password); if (result.Succeeded) { await this.SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); return this.RedirectToAction("Index", "Home"); } this.AddErrors(result); } RegisterViewModel registerModel = new RegisterViewModel() { Header = this.registerHeader, User = userModel }; return View(userModel); }
public async Task<ActionResult> RegisterNewUser(RegisterUserViewModel model) { if (ModelState.IsValid) { var newUser = new User {UserName = model.Email, Email = model.Email}; var createResult = await UserManager.CreateAsync(newUser, model.Password); if (createResult.Succeeded) { await SignInManager.SignInAsync(newUser, false, false); return RedirectToAction("RecentWorkouts", "ActiveUser"); } if (createResult.Errors.Any()) { foreach (var error in createResult.Errors) { ModelState.AddModelError(string.Empty, error); } } } return View(model); }