public async Task <object> Register(UserRegisterModel userRegisterModel) { var user = userRegisterModel.AdaptToUser(); var res = await _unitOfWork.UserManager.CreateAsync(user, userRegisterModel.Password); if (res.Succeeded) { await _unitOfWork.UserManager.AddToRoleAsync(user, userRegisterModel.UserRole); return(GenerateJwtToken(userRegisterModel.Email, user.AdaptToDTO())); } throw new Exception("Registration failed"); }
public async Task <IdentityResult> Register(UserRegisterModel userRegisterModel) { var user = userRegisterModel.AdaptToUser(); var result = await _unitOfWork.UserManager.CreateAsync(user, userRegisterModel.Password); if (result.Succeeded) { await _unitOfWork.UserManager.AddToRoleAsync(user, userRegisterModel.UserRole); await _unitOfWork.SignInManager.SignInAsync(user, false); return(result); } else { return(result); } }