Exemplo n.º 1
0
        public override async Task ReplaceClaimAsync(MangoUser user, Claim claim, Claim newClaim, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

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

            UserEntity userEntity = await FindByNameEntityAsync(user.UserName);

            if (userEntity == null)
            {
                throw new UserNotFoundException(user.UserName);
            }
            int             userid   = userEntity.Id;
            UserClaimEntity oldclaim = await _userDbContext.MangoUserClaims.Where(c => c.UserId == userid && c.ClaimType == claim.Type && c.ClaimValue == claim.Value).SingleOrDefaultAsync();

            if (oldclaim == null)
            {
                throw new ClaimNotFoundException(claim.Type, claim.Value);
            }
            oldclaim.ClaimType  = newClaim.Type;
            oldclaim.ClaimValue = newClaim.Value;
        }
Exemplo n.º 2
0
        public override async Task AddClaimsAsync(MangoUser user, IEnumerable <Claim> claims, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (claims == null)
            {
                throw new ArgumentNullException(nameof(claims));
            }
            MangoUser mangoUser = await FindByNameAsync(user.UserName, cancellationToken);

            int userid = mangoUser.Id;

            foreach (Claim claim in claims)
            {
                UserClaimEntity claimEntity = new UserClaimEntity
                {
                    UserId     = userid,
                    ClaimType  = claim.Type,
                    ClaimValue = claim.Value
                };
                await _userDbContext.AddAsync(claimEntity);
            }
        }