コード例 #1
0
        public async Task ReplaceClaimAsync(TUser user, Claim claim, Claim newClaim, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            var matchedClaims = await userClaimRepository.GetList(user.Id, claim.Value, claim.Type, session);

            foreach (var matchedClaim in matchedClaims)
            {
                matchedClaim.ClaimValue = newClaim.Value;
                matchedClaim.ClaimType  = newClaim.Type;
            }

            var updatedClaims = await userClaimRepository.EditMany(matchedClaims, session);

            foreach (var userClaim in user.Claims)
            {
                foreach (var updatedClaim in updatedClaims)
                {
                    if (userClaim.ClaimType == updatedClaim.ClaimType && userClaim.ClaimValue == updatedClaim.ClaimValue)
                    {
                        userClaim.ClaimValue = updatedClaim.ClaimValue;
                        userClaim.ClaimType  = updatedClaim.ClaimType;
                    }
                }
            }
        }