public async Task AddClaimAsync(TApplicationUser user, Claim claim)
 {
     var userClaim = new TUserClaim {
         UserId = user.Id, ClaimType = claim.Type, ClaimValue = claim.Value
     };
     await userClaimRepository.Add(userClaim, session);
 }
Exemplo n.º 2
0
        public Task AddClaimsAsync(ApplicationUser user, IEnumerable <Claim> claims, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (claims == null)
            {
                throw new ArgumentNullException(nameof(claims));
            }

            var claimEntities = claims.Select(x => GetUserClaimEntity(x, user.Id)).ToList();

            if (!claimEntities.Any())
            {
                return(Task.CompletedTask);
            }

            claimEntities.ForEach(claimEntity =>
            {
                _userClaimRepository.Add(claimEntity);
            });

            return(Task.CompletedTask);
        }
            public async Task<IResult> Handle(CreateUserClaimCommand request, CancellationToken cancellationToken)
            {
                var userClaim = new UserClaim
                {
                    ClaimId = request.ClaimId,
                    UserId = request.UserId
                };
                _userClaimRepository.Add(userClaim);
                await _userClaimRepository.SaveChangesAsync();

                return new SuccessResult(Messages.Added);
            }
Exemplo n.º 4
0
            public async Task <IResult> Handle(CreateUserClaimCommand request, CancellationToken cancellationToken)
            {
                var userClaim = new UserClaim
                {
                    ClaimId = request.ClaimId,
                    UserId  = request.UserId
                };

                _userClaimRepository.Add(userClaim);
                await _userClaimRepository.SaveChangesAsync();

                _cacheManager.Remove($"{CacheKeys.UserIdForClaim}={request.UserId}");

                return(new SuccessResult(Messages.Added));
            }
Exemplo n.º 5
0
        public async Task AddClaimsAsync(TUser user, IEnumerable <Claim> claims, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            var userClaims = claims.Select(c => new TUserClaim {
                UserId = user.Id, ClaimType = c.Type, ClaimValue = c.Value
            });

            foreach (var userClaim in userClaims)
            {
                var newClaim = await userClaimRepository.Add(userClaim, session);

                user.Claims.Add(newClaim);
            }
        }
Exemplo n.º 6
0
        public async Task AddClaimAsync(User user, Claim claim)
        {
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (claim == null)
            {
                throw new ArgumentNullException("claim");
            }

            _userClaimRepository.Add(new UserClaim
            {
                UserId     = user.Id,
                ClaimType  = claim.Type,
                ClaimValue = claim.Value
            });
            await _uow.SaveChangesAsync();
        }
Exemplo n.º 7
0
            public async Task <IResult> Handle(CreateUserClaimsInternalCommand request, CancellationToken cancellationToken)
            {
                foreach (var claim in request.OperationClaims)
                {
                    if (await DoesClaimExistsForUser(new UserClaim {
                        ClaimId = claim.Id, UserId = request.UserId
                    }))
                    {
                        continue;
                    }

                    _userClaimsRepository.Add(new UserClaim
                    {
                        ClaimId = claim.Id,
                        UserId  = request.UserId
                    });
                }
                await _userClaimsRepository.SaveChangesAsync();

                return(new SuccessResult(Messages.Added));
            }