public async Task <IActionResult> Register(AccountRegisterVM viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var user = new IdentityUser(); user.Email = viewModel.Email; user.UserName = viewModel.Email; var result = await userManager.CreateAsync(user, viewModel.Password); if (!result.Succeeded) { if (result.ToString().Contains("DuplicateEmail")) { ModelState.AddModelError(nameof(AccountRegisterVM.Email), "E-posten är redan registrerad"); } if (result.ToString().Contains("DuplicateUserName")) { ModelState.AddModelError(nameof(AccountRegisterVM.Email), "E-posten är redan registrerad"); } return(View(viewModel)); } mysticoContext.AddUser(user.Id, viewModel.FirstName, viewModel.LastName, viewModel.Email); await signInManager.PasswordSignInAsync(user, viewModel.Password, false, false); return(RedirectToAction(nameof(SplitController.Index), nameof(SplitController).Replace("Controller", ""))); }