public async Task <IActionResult> Register([FromBody] RegisterVModel model, string returnUrl = null) { var user = new ApplicationUser(model.Email); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { user.FirstName = model.FirstName; user.LastName = model.LastName; //var role = "Admin"; // model.RegisterAsDoctor ? "Doctor" : "Patient"; var role = model.RegisterAsDoctor ? "Doctor" : "Patient"; var roleAddResult = await _userManager.AddToRoleAsync(user, role); if (roleAddResult.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); await _dataHub.NotifyClients(user, role, model.RegisterAsDoctor); return(Ok()); } else { return(BadRequest(new ValidationError("Unexpected error", "Failed adding to such a role"))); } } AddErrors(result); return(BadRequest(new ApiError(ModelState))); }