Exemple #1
0
        public async Task <ResultModel> CreateConfig(OcelotConfigEditDto dto)
        {
            if (string.IsNullOrWhiteSpace(dto.GlobalConfiguration.BaseUrl))
            {
                return(new ResultModel(ResultCode.Fail, "请输入网关地址"));
            }
            var globalConfiguration = new GlobalConfiguration
            {
                BaseUrl = dto.GlobalConfiguration.BaseUrl
            };
            var ocelotConfig = new OcelotConfig
            {
                IsEnable            = dto.IsEnable,
                GlobalConfiguration = globalConfiguration
            };

            try
            {
                _userDatabaseContext.OcelotConfigs.Add(ocelotConfig);
                await _userDatabaseContext.SaveChangesAsync();

                return(new ResultModel(ResultCode.Success, "创建网关配置成功"));
            }
            catch (Exception ex)
            {
                return(new ResultModel(ResultCode.Fail, ex.Message));
            }
        }
Exemple #2
0
        public async Task <ResultModel <string> > CreateConfig(OcelotConfigEditDto dto)
        {
            var configJson = new StringContent(JsonConvert.SerializeObject(dto), Encoding.UTF8, "application/json");
            var response   = await _httpClient.PostAsync($"api/Ocelot/CreateConfig", configJson);

            if (response.IsSuccessStatusCode)
            {
                return(JsonConvert.DeserializeObject <ResultModel <string> >(await response.Content.ReadAsStringAsync()));
            }
            return(null);
        }
Exemple #3
0
        public async Task <ResultModel> UpdateConfig(OcelotConfigEditDto dto)
        {
            var configModel = await _userDatabaseContext.OcelotConfigs.Include(x => x.GlobalConfiguration).FirstOrDefaultAsync(x => x.Id == dto.Id);

            if (configModel == null)
            {
                return(new ResultModel(ResultCode.Fail, "没有对应网关配置"));
            }
            configModel.IsEnable = dto.IsEnable;
            configModel.GlobalConfiguration.BaseUrl = dto.GlobalConfiguration.BaseUrl;
            try
            {
                _userDatabaseContext.OcelotConfigs.Update(configModel);
                await _userDatabaseContext.SaveChangesAsync();

                return(new ResultModel(ResultCode.Success, "更新网关配置成功"));
            }
            catch (Exception ex)
            {
                return(new ResultModel(ResultCode.Fail, ex.Message));
            }
        }
 public async Task <IActionResult> CreateConfig([FromBody] OcelotConfigEditDto dto)
 {
     return(Json(await _ocelotConfigService.CreateConfig(dto)));
 }