public async Task <ActionResult> Handle(RegisterCommand request, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); _unitOfWork.BeginTransaction(); var appUser = _mapper.Map <AppIdentityUser>(request.User); var result = await _identityUserManager.CreateAsync(appUser, request.Password); if (result.Succeeded) { var userPrincipal = await _signInManager.CreateUserPrincipalAsync(appUser); var userId = int.Parse(_identityUserManager.GetUserId(userPrincipal)); await _signInManager.SignInAsync(appUser, true); _unitOfWork.Commit(); return(new ActionResult { Suceeded = true }); } else { _unitOfWork.Rollback(); return(new ActionResult { Suceeded = false, ErrorMessages = result.Errors.Select(x => x.Description).ToList() }); } }