コード例 #1
0
        public async Task <string> CreateAsync(ScopeParam model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var entity = await _manager.FindByNameAsync(model.Name);

            if (entity == null)
            {
                // create new entity
                var newEntity = new OpenIddictEntityFrameworkCoreScope
                {
                    Name        = model.Name,
                    DisplayName = model.DisplayName,
                    Description = model.Description
                };

                HandleCustomProperties(model, newEntity);

                await _manager.CreateAsync(newEntity);

                return(newEntity.Id);
            }

            // update existing entity
            model.Id = entity.Id;
            await UpdateAsync(model);

            return(entity.Id);
        }
コード例 #2
0
 private void HandleCustomProperties(
     ScopeParam model,
     OpenIddictEntityFrameworkCoreScope entity
     )
 {
     entity.Resources = JsonSerializer.Serialize(model.Resources);
 }
コード例 #3
0
        public async Task UpdateAsync(ScopeParam model)
        {
            if (string.IsNullOrWhiteSpace(model.Id))
            {
                throw new ArgumentNullException(nameof(model.Id));
            }

            var entity = await _manager.FindByIdAsync(model.Id);

            SimpleMapper.Map <ScopeParam, OpenIddictEntityFrameworkCoreScope>(model, entity);

            HandleCustomProperties(model, entity);

            await _manager.UpdateAsync(entity);
        }