Skip to content

Commit

Permalink
Multiple users invitation fix (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
getmansky authored Aug 17, 2022
1 parent 3b82d77 commit 07b5f70
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ public InviteUserCommandHandler(

public virtual async Task<IdentityResultResponse> Handle(InviteUserCommand request, CancellationToken cancellationToken)
{
using var userManager = _userManagerFactory();

var result = new IdentityResultResponse
{
Errors = new List<IdentityErrorInfo>(),
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<string> { 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);
Expand All @@ -87,7 +87,7 @@ public virtual async Task<IdentityResultResponse> Handle(InviteUserCommand reque
}

result.Errors.AddRange(identityResult.Errors.Select(x => x.MapToIdentityErrorInfo()));
result.Succeeded &= identityResult.Succeeded;
result.Succeeded |= identityResult.Succeeded;

if (!result.Succeeded)
{
Expand Down

0 comments on commit 07b5f70

Please sign in to comment.