public ActionResult Register(UserRegisterModel model) { var anyUser = _userService.GetAll().Any(u => u.Email == model.Email); if (anyUser) { ModelState.AddModelError("", "User with that email already exists!"); return(View(model)); } if (ModelState.IsValid) { var user = new User() { Password = model.Password, Email = model.Email }; user = _userService.Create(user); if (user != null) { _signService.IdentitySignin(user); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Registration error!"); } } return(View("Register")); }
public ActionResult Register(UserRegisterModel model) { if (ModelState.IsValid) { var user = new UserEntity() { Name = model.Name, Password = model.Password, Roles = new List <RoleEntity>() { new RoleEntity() { Id = 3 } } }; user = _userService.CreateUser(user); if (user != null) { _signService.IdentitySignin(user); return(RedirectToAction("Index", "Home", null)); } ViewBag.Error = "This user already exists"; return(View("Register")); } ViewBag.Error = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage));; return(View("Register")); }