protected async Task <bool> OnSaveAsync(ApiScopeDto dto)
        {
            ResultModel <string> result = new ResultModel <string>();
            var model = new ApiScopeEditDto()
            {
                Enabled     = dto.Enabled,
                Name        = dto.Name,
                DisplayName = dto.DisplayName,
                Description = dto.Description
            };

            if (dto.Id == null)
            {
                model.Id = 0;
                result   = await ApiScopeService.AddApiScope(model);
            }
            else
            {
                model.Id = dto.Id;
                result   = await ApiScopeService.EditApiScope(model);
            }
            if (result.status.code == ResultCode.Success)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        public async Task <ResultModel <string> > EditApiScope(ApiScopeEditDto dto)
        {
            var apiJson  = new StringContent(JsonConvert.SerializeObject(dto), Encoding.UTF8, "application/json");
            var response = await _httpClient.PostAsync($"api/ApiScope/UpdateApiScope", apiJson);

            if (response.IsSuccessStatusCode)
            {
                return(JsonConvert.DeserializeObject <ResultModel <string> >(await response.Content.ReadAsStringAsync()));
            }
            return(null);
        }
Exemple #3
0
        public async Task <ResultModel> CreateApiScope(ApiScopeEditDto dto)
        {
            try
            {
                List <ApiScopeClaim> apiScopeClaims = new List <ApiScopeClaim>();
                foreach (var item in dto.UserClaims)
                {
                    apiScopeClaims.Add(new ApiScopeClaim
                    {
                        Type = item.Type
                    });
                }

                var apiScope = new ApiScope
                {
                    Enabled                 = dto.Enabled,
                    Name                    = dto.Name,
                    DisplayName             = dto.DisplayName,
                    Description             = dto.Description,
                    Required                = dto.Required,
                    Emphasize               = dto.Emphasize,
                    ShowInDiscoveryDocument = dto.ShowInDiscoveryDocument,
                    UserClaims              = apiScopeClaims
                };

                //List<ApiScopeProperty> apiScopeProperties = new List<ApiScopeProperty>();
                //foreach (var item in apiScopeCreateDto.Properties)
                //{
                //    apiScopeProperties.Add(new ApiScopeProperty
                //    {
                //        Key = item.Key,
                //        Value = item.Value
                //    });
                //}
                //apiScope.Properties = apiScopeProperties;

                _userDatabaseContext.ApiScopes.Add(apiScope);
                await _userDatabaseContext.SaveChangesAsync();

                return(new ResultModel(ResultCode.Success, "创建API域成功"));
            }
            catch (Exception ex)
            {
                return(new ResultModel(ResultCode.Fail, ex.Message));
            }
        }
Exemple #4
0
        public async Task <ResultModel> UpdateApiScope(ApiScopeEditDto dto)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(dto.Name))
                {
                    return(new ResultModel(ResultCode.Fail, "请输入API域名称"));
                }
                var apiScope = await _userDatabaseContext.ApiScopes.Where(x => x.Id == dto.Id)
                               .Include(x => x.UserClaims)
                               .FirstOrDefaultAsync();

                List <ApiScopeClaim> apiScopeClaims = new List <ApiScopeClaim>();
                foreach (var item in dto.UserClaims)
                {
                    apiScopeClaims.Add(new ApiScopeClaim
                    {
                        Type = item.Type
                    });
                }
                apiScope.Enabled                 = dto.Enabled;
                apiScope.Name                    = dto.Name;
                apiScope.DisplayName             = dto.DisplayName;
                apiScope.Description             = dto.Description;
                apiScope.Required                = dto.Required;
                apiScope.Emphasize               = dto.Emphasize;
                apiScope.ShowInDiscoveryDocument = dto.ShowInDiscoveryDocument;
                apiScope.UserClaims              = apiScopeClaims;

                _userDatabaseContext.ApiScopes.Update(apiScope);
                await _userDatabaseContext.SaveChangesAsync();

                return(new ResultModel(ResultCode.Success, "更新API域成功"));
            }
            catch (Exception ex)
            {
                return(new ResultModel(ResultCode.Fail, ex.Message));
            }
        }
 public async Task <IActionResult> UpdateApiScope([FromBody] ApiScopeEditDto dto)
 {
     return(Json(await _apiScopeService.UpdateApiScope(dto)));
 }