Beispiel #1
0
 public static IdentityUserClaim <string> ToUserClaim(this Entity.UserClaim claim)
 {
     return(new IdentityUserClaim <string>
     {
         Id = claim.Id != null?int.Parse(claim.Id) : 0,
                  UserId = claim.UserId,
                  ClaimType = claim.ClaimType,
                  ClaimValue = claim.ClaimValue
     });
 }
 public static UserClaim ToUserClaim(this Entity.UserClaim claim)
 {
     return(new UserClaim
     {
         Id = claim.Id != null?int.Parse(claim.Id) : 0,
                  UserId = claim.UserId,
                  ClaimType = claim.ClaimType,
                  ClaimValue = claim.ClaimValue,
                  Issuer = claim.Issuer,
                  OriginalType = claim.OriginalType
     });
 }
        public static UserClaim ToUserClaim(this Entity.UserClaim claim)
        {
            if (!int.TryParse(claim.Id, out int id))
            {
                id = 0;
            }

            return(new UserClaim
            {
                Id = id,
                UserId = claim.UserId,
                ClaimType = claim.ClaimType,
                ClaimValue = claim.ClaimValue,
                Issuer = claim.Issuer,
                OriginalType = claim.OriginalType
            });
        }
        public async Task <Entity.UserClaim> UpdateAsync(Entity.UserClaim entity, CancellationToken cancellationToken = default)
        {
            var claim = await GetClaimAsync(entity.Id, cancellationToken).ConfigureAwait(false);

            var user = await GetUserAsync(entity.UserId)
                       .ConfigureAwait(false);

            var result = await _userManager.RemoveClaimAsync(user, claim.ToClaim())
                         .ConfigureAwait(false);

            ChechResult(result);
            result = await _userManager.AddClaimAsync(user, entity.ToUserClaim().ToClaim())
                     .ConfigureAwait(false);

            ChechResult(result);
            _logger.LogInformation("Entity {EntityId} updated", entity.Id, entity);
            return(entity);
        }
        public async Task <Entity.UserClaim> CreateAsync(Entity.UserClaim entity, CancellationToken cancellationToken = default)
        {
            var user = await GetUserAsync(entity.UserId)
                       .ConfigureAwait(false);

            var claim  = entity.ToUserClaim().ToClaim();
            var result = await _userManager.AddClaimAsync(user, claim)
                         .ConfigureAwait(false);

            if (result.Succeeded)
            {
                entity.Id = Guid.NewGuid().ToString();
                _logger.LogInformation("Entity {EntityId} created", entity.Id, entity);
                return(entity);
            }
            throw new IdentityException
                  {
                      Errors = result.Errors
                  };
        }
        public async Task <Entity.UserClaim> UpdateAsync(Entity.UserClaim entity, CancellationToken cancellationToken = default)
        {
            var claim = await GetClaimAsync(entity.Id, cancellationToken).ConfigureAwait(false);

            if (claim == null)
            {
                throw new DbUpdateException($"Entity type {typeof(UserClaim).Name} at id {entity.Id} is not found");
            }

            var user = await GetUserAsync(entity.UserId)
                       .ConfigureAwait(false);

            var result = await _userManager.RemoveClaimAsync(user, claim.ToClaim())
                         .ConfigureAwait(false);

            ChechResult(result);
            result = await _userManager.AddClaimAsync(user, entity.ToUserClaim().ToClaim())
                     .ConfigureAwait(false);

            ChechResult(result);
            _logger.LogInformation("Entity {EntityId} updated", entity.Id, entity);
            return(entity);
        }
Beispiel #7
0
 private static Claim ToClaim(Entity.UserClaim userClaim)
 {
     return(new Claim(userClaim.ClaimType, userClaim.ClaimValue, null, userClaim.Issuer));
 }
Beispiel #8
0
 private void OnDeleteClaimClicked(entity.UserClaim claim)
 {
     Model.Claims.Remove(claim);
     EntityDeleted(claim);
     StateHasChanged();
 }