private ApiResource BuildApiResource(ApiResourceCreateDto form)
        {
            ApiResource resource = new ApiResource
            {
                Description = form.Description,
                DisplayName = form.DisplayName,
                Name        = form.Name
            };

            if (form.Scopes != null && form.Scopes.Any())
            {
                resource.Scopes = form
                                  .Scopes
                                  .Select(s => new ApiScope {
                    Name = s
                })
                                  .ToList();
            }

            if (form.UserClaims != null && form.UserClaims.Any())
            {
                resource.UserClaims = form
                                      .UserClaims
                                      .Select(c => new ApiResourceClaim {
                    Type = c
                })
                                      .ToList();
            }

            return(resource);
        }
        public async Task <IActionResult> Create([FromBody] ApiResourceCreateDto form)
        {
            await _apiResourceService.Create(form);

            string uri = Url.Action(nameof(GetByName), new { form.Name });

            return(Created(uri, null));
        }
        public async Task Create(ApiResourceCreateDto dto)
        {
            EnsureModelValid(dto);

            ApiResource existResource = await FindByName(dto.Name);

            if (existResource != null)
            {
                throw new BadRequestException($"ApiResource with name '{dto.Name}' already exist.");
            }

            ApiResource resource = BuildApiResource(dto);

            _apiResourceRepository.Add(resource);
            await _apiResourceRepository.SaveChangesAsync();
        }