diff --git a/src/VirtoCommerce.ProfileExperienceApiModule.Data/Commands/InviteUserCommandHandler.cs b/src/VirtoCommerce.ProfileExperienceApiModule.Data/Commands/InviteUserCommandHandler.cs index 7afaf67d..44ac1050 100644 --- a/src/VirtoCommerce.ProfileExperienceApiModule.Data/Commands/InviteUserCommandHandler.cs +++ b/src/VirtoCommerce.ProfileExperienceApiModule.Data/Commands/InviteUserCommandHandler.cs @@ -47,23 +47,23 @@ public InviteUserCommandHandler( public virtual async Task Handle(InviteUserCommand request, CancellationToken cancellationToken) { - using var userManager = _userManagerFactory(); - var result = new IdentityResultResponse { Errors = new List(), - Succeeded = true, + Succeeded = false, }; // PT-6083: reduce complexity foreach (var email in request.Emails) { + using var userManager = _userManagerFactory(); + var contact = new Contact { FirstName = string.Empty, LastName = string.Empty, FullName = string.Empty, Organizations = new List { request.OrganizationId } }; await _memberService.SaveChangesAsync(new Member[] { contact }); var user = new ApplicationUser { UserName = email, Email = email, MemberId = contact.Id, StoreId = request.StoreId }; var identityResult = await userManager.CreateAsync(user); - + if (identityResult.Succeeded) { var store = await _storeService.GetByIdAsync(user.StoreId); @@ -87,7 +87,7 @@ public virtual async Task Handle(InviteUserCommand reque } result.Errors.AddRange(identityResult.Errors.Select(x => x.MapToIdentityErrorInfo())); - result.Succeeded &= identityResult.Succeeded; + result.Succeeded |= identityResult.Succeeded; if (!result.Succeeded) {