public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = Mapper.Map <User>(model); if (_usersService.GetUserByUsername(user.Username) != null) { ModelState.AddModelError("", "This username already exists.\n\nPlease try another username."); } else if (_usersService.GetUserByEmail(user.Email) != null) { ModelState.AddModelError("", string.Format("This E-mail address has already been registered.\n\nIf this is your e-mail address, click <a href=\"{0}\">here</a> to reset.", Services.SiteInfo.FORGOT_PASSWORD_LINK)); } else { var newUser = _usersService.AddReturnEntity(user); if (ModelState.IsValid) { _authentication.Login(newUser, true); return(RedirectToAction("Index", "Home")); } } } // If we got this far, something failed, redisplay form return(View(model)); }