示例#1
0
        public async Task UpdateAsync(IdentityResource identityResource)
        {
            var dbItem = GetByName(identityResource.Name);

            if (dbItem == null)
            {
                throw new InvalidOperationException($"Could not find IdentityResource with name {identityResource.Name}. Update failed.");
            }

            var entity = identityResource.MapIdentityResources();

            entity.Id           = dbItem.Id;
            await using var con = new SqlConnection(_connectionString);
            await con.OpenAsync();

            await using var t = await con.BeginTransactionAsync();

            try
            {
                var ret = await con.ExecuteAsync($"update {_options.DbSchema}.IdentityResources set [Description] = @Description," +
                                                 "DisplayName=@DisplayName," +
                                                 "Enabled=@Enabled," +
                                                 "Emphasize=@Emphasize," +
                                                 "[Name]=@Name," +
                                                 "Required=@Required," +
                                                 "ShowInDiscoveryDocument=@ShowInDiscoveryDocument where Id=@Id;", entity, commandType : CommandType.Text, transaction : t);
                await UpdateClaims(identityResource.UserClaims, entity.Id, con, t);

                await t.CommitAsync();
            }
            catch (Exception)
            {
                await t.RollbackAsync();

                throw;
            }
        }