public async Task <IActionResult> UpdateKnowledge(UpdateKnowledgeViewModel vm) { var model = await _answerService.GetAsync(vm.Id); if (model != null) { model.Intent = vm.Intent; model.RequestUrl = vm.RequestUrl; model.Answer = vm.Answer ?? vm.FlowId; model.Method = vm.Method; model.FlowId = vm.FlowId; model.AnswerType = (AnswerTypes)vm.AnswerType; // 先删除原来的 await _answerService.RemoveParameters(model.Id); if (vm.ParameterIds?.Count > 0) { List <AnswerQueries> parameters = new List <AnswerQueries>(); foreach (var parameter in vm.ParameterIds) { parameters.Add(new AnswerQueries { AnswerId = model.Id, ParameterId = parameter }); } await _answerService.AddParameters(parameters); } await _answerService.UpdateAllProperties(model); var result = await _answerService.SaveChangesAsync(); return(result ? Ok() : (IActionResult)BadRequest()); } return(NotFound()); }