示例#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
    public async Task UpdateAsync(ScopeParam model)
    {
        if (string.IsNullOrWhiteSpace(model.Id))
        {
            throw new InvalidOperationException(nameof(model.Id));
        }

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

        SimpleMapper.Map(model, entity);

        HandleCustomProperties(model, entity);

        await _manager.UpdateAsync(entity);
    }
示例#3
0
 private static void HandleCustomProperties(
     ScopeParam model,
     OpenIddictEntityFrameworkCoreScope entity
     ) => entity.Resources = JsonSerializer.Serialize(model.Resources);