public async Task <IActionResult> ApiResource(ApiResourceDto apiResource)
        {
            if (!ModelState.IsValid)
            {
                return(View(apiResource));
            }

            ComboBoxHelpers.PopulateValuesToList(apiResource.UserClaimsItems, apiResource.UserClaims);

            int apiResourceId;

            if (apiResource.Id == 0)
            {
                apiResourceId = await _apiResourceService.AddApiResourceAsync(apiResource);
            }
            else
            {
                apiResourceId = apiResource.Id;
                await _apiResourceService.UpdateApiResourceAsync(apiResource);
            }

            SuccessNotification(string.Format(_localizer["SuccessAddApiResource"], apiResource.Name), _localizer["SuccessTitle"]);

            return(RedirectToAction(nameof(ApiResource), new { Id = apiResourceId }));
        }
        public async Task <IActionResult> Post([FromBody] ApiResourceApiDto apiResourceApi)
        {
            var apiResourceDto = apiResourceApi.ToApiResourceApiModel <ApiResourceDto>();
            await _apiResourceService.AddApiResourceAsync(apiResourceDto);

            return(Ok());
        }
Esempio n. 3
0
        public async Task <IActionResult> ApiResource(ApiResourceDto apiResource)
        {
            if (!ModelState.IsValid)
            {
                return(Success(apiResource));
            }

            ComboBoxHelpers.PopulateValuesToList(apiResource.UserClaimsItems, apiResource.UserClaims);

            int apiResourceId;

            if (apiResource.Id == 0)
            {
                apiResourceId = await _apiResourceService.AddApiResourceAsync(apiResource);
            }
            else
            {
                apiResourceId = apiResource.Id;
                await _apiResourceService.UpdateApiResourceAsync(apiResource);
            }



            return(Success(new { Id = apiResourceId }));
        }
        public async Task <IActionResult> New([FromBody] ApiResource apiResource)
        {
            if (!IsValidResource(apiResource))
            {
                return(Error());
            }

            var success = await _service.AddApiResourceAsync(apiResource);

            if (success)
            {
                return(Success());
            }
            return(Error());
        }
Esempio n. 5
0
        public async Task <IActionResult> SaveApiResource([FromBody] ApiResourceRegistryDto api)
        {
            ApiResourcesDto targ = await _apiResourceService.GetApiResourcesAsync(api.Name, 1, 1);

            ApiResourceDto apiDto = ToApiResourceDto(api);
            int            apiId;

            if (targ.ApiResources.Count == 0)
            {
                apiId = await _apiResourceService.AddApiResourceAsync(apiDto);
            }
            else
            {
                apiId     = targ.ApiResources[0].Id;
                apiDto.Id = apiId;
                await _apiResourceService.UpdateApiResourceAsync(apiDto);
            }

            ApiScopesDto scopesInDb = await _apiResourceService.GetApiScopesAsync(apiId, 1, int.MaxValue);

            foreach (var sitem in api.Scopes)
            {
                if (scopesInDb.Scopes.Any(x => x.Name == sitem.Name))
                {
                    continue;
                }

                await _apiResourceService.AddApiScopeAsync(new ApiScopesDto()
                {
                    ApiResourceId           = apiId,
                    Description             = sitem.Description,
                    DisplayName             = sitem.DisplayName,
                    Emphasize               = sitem.Emphasize,
                    Name                    = sitem.Name,
                    Required                = sitem.Required,
                    ShowInDiscoveryDocument = sitem.ShowInDiscoveryDocument,
                    UserClaims              = sitem.UserClaims,
                });
            }

            foreach (var sitem in scopesInDb.Scopes)
            {
                if (api.Scopes.Any(x => x.Name == sitem.Name))
                {
                    continue;
                }

                var apiScope = new ApiScopesDto {
                    ApiResourceId = apiId, ApiScopeId = sitem.Id
                };
                await _apiResourceService.DeleteApiScopeAsync(apiScope);
            }

            ApiResourcePropertiesDto propertiesDto = await _apiResourceService.GetApiResourcePropertiesAsync(apiId, 1, int.MaxValue);

            ApiResourcePropertiesDto[] todele = propertiesDto.ApiResourceProperties.Where(x => api.Properties.ContainsKey(x.Key))
                                                .Select(x => new ApiResourcePropertiesDto()
            {
                ApiResourceId         = apiId,
                ApiResourcePropertyId = x.Id,
                Key   = x.Key,
                Value = x.Value
            }).ToArray();

            foreach (var prop in todele)
            {
                await _apiResourceService.DeleteApiResourcePropertyAsync(prop);
            }

            foreach (var item in api.Properties)
            {
                await _apiResourceService.AddApiResourcePropertyAsync(new ApiResourcePropertiesDto
                {
                    ApiResourceId = apiId,
                    Key           = item.Key,
                    Value         = item.Value
                });
            }

            return(Ok());
        }