public async Task<IActionResult> Register(UserRegister model, string returnUrl = null) { if (ModelState.IsValid) { var checkUser = await _userManager.FindByEmailAsync(model.Email); if(checkUser != null) { ModelState.AddModelError("","Email already exists"); return View(model); } User user = new User { Name = model.Name, Designation = model.Designation, Role = model.Role, Location = model.Location, ProfileImage = "assets/images/users.png" }; long userId = _userServices.AddNewuser(user); var appUser = new AppUser { UserName = model.Email, Email = model.Email, UserId = userId }; var result = await _userManager.CreateAsync(appUser, model.Password); if (result.Succeeded) { await _signInManager.SignInAsync(appUser, isPersistent: false); if (returnUrl == null) return Redirect("~/home"); return Redirect(returnUrl); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } return View(model); }