public async Task <RoleClaim> UpdateAsync(RoleClaim entity, CancellationToken cancellationToken = default) { var claim = await GetClaimAsync(entity.Id, cancellationToken).ConfigureAwait(false); var role = await GetRoleAsync(claim.RoleId) .ConfigureAwait(false); var result = await _roleManager.RemoveClaimAsync(role, claim.ToClaim()) .ConfigureAwait(false); ChechResult(result, entity); result = await _roleManager.AddClaimAsync(role, entity.ToRoleClaim().ToClaim()) .ConfigureAwait(false); _logger.LogInformation("Entity {EntityId} updated", entity.Id, entity); return(ChechResult(result, entity)); }
public async Task <RoleClaim> CreateAsync(RoleClaim entity, CancellationToken cancellationToken = default) { var role = await GetRoleAsync(entity.RoleId) .ConfigureAwait(false); var claim = entity.ToRoleClaim().ToClaim(); var result = await _roleManager.AddClaimAsync(role, claim) .ConfigureAwait(false); if (result.Succeeded) { entity.Id = role.Id; _logger.LogInformation("Entity {EntityId} created", entity.Id, entity); return(entity); } throw new IdentityException { Errors = result.Errors }; }
public async Task <RoleClaim> UpdateAsync(RoleClaim entity, CancellationToken cancellationToken = default) { var claim = await GetClaimAsync(entity.Id, cancellationToken).ConfigureAwait(false); if (claim == null) { throw new DbUpdateException($"Entity type {typeof(RoleClaim).Name} at id {entity.Id} is not found"); } var role = await GetRoleAsync(claim.RoleId) .ConfigureAwait(false); var result = await _roleManager.RemoveClaimAsync(role, claim.ToClaim()) .ConfigureAwait(false); ChechResult(result, entity); result = await _roleManager.AddClaimAsync(role, entity.ToRoleClaim().ToClaim()) .ConfigureAwait(false); _logger.LogInformation("Entity {EntityId} updated", entity.Id, entity); return(ChechResult(result, entity)); }