public async Task <IActionResult> ApiScopeDelete(ApiScopesDto apiScope) { await _apiResourceService.DeleteApiScopeAsync(apiScope); SuccessNotification(_localizer["SuccessDeleteApiScope"], _localizer["SuccessTitle"]); return(RedirectToAction(nameof(ApiScopes), new { Id = apiScope.ApiResourceId })); }
private async Task BuildApiScopesViewModel(ApiScopesDto apiScope) { if (apiScope.ApiScopeId == 0) { var apiScopesDto = await GetApiScopesAsync(apiScope.ApiResourceId); apiScope.Scopes.AddRange(apiScopesDto.Scopes); apiScope.TotalCount = apiScopesDto.TotalCount; } }
public virtual async Task <int> DeleteApiScopeAsync(ApiScopesDto apiScope) { var scope = apiScope.ToEntity(); var deleted = await ApiResourceRepository.DeleteApiScopeAsync(scope); await AuditEventLogger.LogEventAsync(new ApiScopeDeletedEvent(apiScope)); return(deleted); }
public async Task <IActionResult> DeleteScope(int id, int apiScopeId) { var apiScope = new ApiScopesDto { ApiResourceId = id, ApiScopeId = apiScopeId }; await _apiResourceService.GetApiResourceAsync(apiScope.ApiResourceId); await _apiResourceService.GetApiScopeAsync(apiScope.ApiResourceId, apiScope.ApiScopeId); await _apiResourceService.DeleteApiScopeAsync(apiScope); return(Ok()); }
public async Task <int> UpdateApiScopeAsync(ApiScopesDto apiScope) { var canInsert = await CanInsertApiScopeAsync(apiScope); if (!canInsert) { await BuildApiScopesViewModel(apiScope); throw new UserFriendlyViewException(string.Format(_apiResourceServiceResources.ApiScopeExistsValue().Description, apiScope.Name), _apiResourceServiceResources.ApiScopeExistsKey().Description, apiScope); } var scope = apiScope.ToEntity(); return(await _apiResourceRepository.UpdateApiScopeAsync(apiScope.ApiResourceId, scope)); }
public virtual async Task <int> AddApiScopeAsync(ApiScopesDto apiScope) { var canInsert = await CanInsertApiScopeAsync(apiScope); if (!canInsert) { await BuildApiScopesViewModelAsync(apiScope); throw new UserFriendlyViewException(string.Format(ApiResourceServiceResources.ApiScopeExistsValue().Description, apiScope.Name), ApiResourceServiceResources.ApiScopeExistsKey().Description, apiScope); } var scope = apiScope.ToEntity(); var added = await ApiResourceRepository.AddApiScopeAsync(apiScope.ApiResourceId, scope); await AuditEventLogger.LogEventAsync(new ApiScopeAddedEvent(apiScope)); return(added); }
public async Task <IActionResult> ApiScopes(ApiScopesDto apiScope) { if (!ModelState.IsValid) { return(View(apiScope)); } _apiResourceService.BuildApiScopeViewModel(apiScope); if (apiScope.ApiScopeId == 0) { await _apiResourceService.AddApiScopeAsync(apiScope); } else { await _apiResourceService.UpdateApiScopeAsync(apiScope); } SuccessNotification(string.Format(_localizer["SuccessAddApiScope"], apiScope.Name), _localizer["SuccessTitle"]); return(RedirectToAction(nameof(ApiScopes))); }
public ApiScopeRequestedEvent(ApiScopesDto apiScopes) { ApiScopes = apiScopes; }
public async Task <bool> CanInsertApiScopeAsync(ApiScopesDto apiScopes) { var apiScope = apiScopes.ToEntity(); return(await _apiResourceRepository.CanInsertApiScopeAsync(apiScope)); }
public async Task <int> DeleteApiScopeAsync(ApiScopesDto apiScope) { var scope = apiScope.ToEntity(); return(await _apiResourceRepository.DeleteApiScopeAsync(scope)); }
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()); }
public ApiScopeDeletedEvent(ApiScopesDto apiScope) { ApiScope = apiScope; }
public ApiScopeAddedEvent(ApiScopesDto apiScope) { ApiScope = apiScope; }
public ApiScopeUpdatedEvent(ApiScopesDto originalApiScope, ApiScopesDto apiScope) { OriginalApiScope = originalApiScope; ApiScope = apiScope; }
public static ApiScope ToEntity(this ApiScopesDto resource) { return(resource == null ? null : Mapper.Map <ApiScope>(resource)); }
public ApiScopeRequestedEvent(ApiScopesDto apiScope) { ApiScope = apiScope; }
public ApiScopesDto BuildApiScopeViewModel(ApiScopesDto apiScope) { ComboBoxHelpers.PopulateValuesToList(apiScope.UserClaimsItems, apiScope.UserClaims); return(apiScope); }