Ejemplo n.º 1
0
        private async Task UpdatePropertyAsync(string clientId, ClientRegisteration registration, PageResponse <ClientProperty> propertiesResponse, string values, string key)
        {
            var property = propertiesResponse.Items.FirstOrDefault(p => p.Key == key);

            if ((registration.Contacts == null || !registration.Contacts.Any()) && property != null)
            {
                await _clientPropertyStore.DeleteAsync(property.Id).ConfigureAwait(false);
            }
            if (registration.Contacts == null || !registration.Contacts.Any())
            {
                if (property == null)
                {
                    await _clientPropertyStore.CreateAsync(new ClientProperty
                    {
                        ClientId = clientId,
                        Id       = Guid.NewGuid().ToString(),
                        Key      = key,
                        Value    = values
                    }).ConfigureAwait(false);
                }
                else if (property.Value != values)
                {
                    property.Value = values;
                    await _clientPropertyStore.UpdateAsync(property).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 2
0
        protected async Task UpdateAsync(string handle, TDto dto, DateTime?expiration)
        {
            var entity = await GetEntityByHandle(handle)
                         .ConfigureAwait(false);

            if (entity == null)
            {
                throw new InvalidOperationException($"{dto.GetType().Name} {handle} not found");
            }

            var subjectId = GetSubjectId(dto);
            var clientId  = GetClientId(dto);

            var newEntity = CreateEntity(dto, clientId, subjectId, expiration);

            entity.Data = newEntity.Data;

            await _store.UpdateAsync(entity).ConfigureAwait(false);
        }
Ejemplo n.º 3
0
        private async Task UpdateClient(ClientRegisteration registration, Client client)
        {
            client.ClientUri = registration.ClientUris?.FirstOrDefault(u => u.Culture == null)?.Value ??
                               registration.ClientUris?.FirstOrDefault()?.Value;
            client.LogoUri = registration.LogoUris?.FirstOrDefault(u => u.Culture == null)?.Value ??
                             registration.LogoUris?.FirstOrDefault()?.Value;
            client.PolicyUri = registration.TosUris?.FirstOrDefault(u => u.Culture == null)?.Value ??
                               registration.TosUris?.FirstOrDefault()?.Value;
            client.TosUri = registration.TosUris?.FirstOrDefault(u => u.Culture == null)?.Value ??
                            registration.TosUris?.FirstOrDefault()?.Value;

            await _clientStore.UpdateAsync(client).ConfigureAwait(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Updates a role in a store as an asynchronous operation.
        /// </summary>
        /// <param name="role">The role to update in the store.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
        /// <returns>A <see cref="Task{TResult}"/> that represents the <see cref="IdentityResult"/> of the asynchronous query.</returns>
        public async virtual Task <IdentityResult> UpdateAsync(TRole role, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            AssertNotNull(role, nameof(role));


            try
            {
                await _roleStore.UpdateAsync(role.ToRole(), cancellationToken).ConfigureAwait(false);

                return(IdentityResult.Success);
            }
            catch (Exception e)
            {
                return(IdentityResult.Failed(new IdentityError
                {
                    Code = e.GetType().Name,
                    Description = e.Message
                }));
            }
        }
Ejemplo n.º 5
0
        private async Task <TEntity> CreateEntityGraphAsync(IEnumerable <PropertyInfo> navigationProperties, ServiceProvider provider, IAdminStore <TEntity> sut)
        {
            var create = new TEntity
            {
                Id = Guid.NewGuid().ToString()
            };
            var parentPropetyName = GetParentIdName(create.GetType());

            if (parentPropetyName != null)
            {
                var parentPropetyType = GetParentType(parentPropetyName);
                await AddParentEntity(provider, create, parentPropetyName, parentPropetyType).ConfigureAwait(false);
            }
            var entity = await sut.CreateAsync(create).ConfigureAwait(false);

            foreach (var property in navigationProperties)
            {
                var subEntityType = property.PropertyType;
                if (subEntityType.ImplementsGenericInterface(typeof(ICollection <>)))
                {
                    subEntityType = subEntityType.GetGenericArguments()[0];
                    var parentPropety = subEntityType.GetProperty(GetSubEntityParentIdName(entity.GetType()));
                    var subEntity     = Activator.CreateInstance(subEntityType);
                    parentPropety.SetValue(subEntity, entity.Id);

                    var storeType = typeof(IAdminStore <>).MakeGenericType(subEntityType);
                    var subStore  = provider.GetRequiredService(storeType) as IAdminStore;
                    await subStore.CreateAsync(subEntity).ConfigureAwait(false);

                    continue;
                }

                await AddParentEntity(provider, create, $"{property.Name}Id", property.PropertyType).ConfigureAwait(false);
            }
            await sut.UpdateAsync(entity).ConfigureAwait(false);

            return(entity);
        }
Ejemplo n.º 6
0
            private async Task AddOrUpdateEntityAsync(T entity, IAdminStore <T> store, ImportFileResult result)
            {
                var subEntities = GetSubEntities(entity);
                var existing    = await store.GetAsync(entity.Id, null).ConfigureAwait(false);

                if (existing != null)
                {
                    entity = await store.UpdateAsync(entity).ConfigureAwait(false);

                    result.Updated.Add(entity.Id);
                }
                else
                {
                    entity = await store.CreateAsync(entity).ConfigureAwait(false);

                    result.Created.Add(entity.Id);
                }

                var subResults = new ImportFileResult();

                result.SubEntitiesResults.Add(entity.Id, subResults);
                await ImportSubEntitiesAsync(entity, subEntities, store, subResults).ConfigureAwait(false);
            }
Ejemplo n.º 7
0
        public async Task UpdateByUserCodeAsync(string userCode, Models.DeviceCode data)
        {
            userCode = userCode ?? throw new ArgumentNullException(nameof(userCode));
            data     = data ?? throw new ArgumentNullException(nameof(data));

            var response = await _store.GetAsync(new PageRequest
            {
                Filter = $"{nameof(DeviceCode.UserCode)} eq '{userCode}'"
            }).ConfigureAwait(false);

            if (response.Items.Any())
            {
                var entity = response.Items.First();
                entity.Data       = _serializer.Serialize(data);
                entity.Expiration = data.CreationTime.AddSeconds(data.Lifetime);
                entity.SubjectId  = data.Subject?.FindFirst(JwtClaimTypes.Subject).Value;
                await _store.UpdateAsync(entity).ConfigureAwait(false);

                return;
            }

            throw new InvalidOperationException($"Device code for {userCode} not found");
        }
Ejemplo n.º 8
0
 public async Task <User> UpdateAsync(User entity, CancellationToken cancellationToken = default)
 {
     return(User.FromEntity(await _store.UpdateAsync(entity, cancellationToken)
                            .ConfigureAwait(false)));
 }
Ejemplo n.º 9
0
 public Task UpdateAsync(TSchemeDefinition definition, CancellationToken cancellationToken = default)
 {
     return(_store.UpdateAsync(ToEntity(definition), cancellationToken));
 }