public async Task <HandleResult> FieldEdit([FromBody] ModelField model) { if (model.Id <= 0) { if (model.ModelNum.IsEmpty()) { return(HandleResult.Error("请选择模型")); } if (model.Name.IsEmpty()) { return(HandleResult.Error("请填写名称")); } } var isUpdate = model.Id > 0; var info = isUpdate ? await _modelFieldService.GetById(model.Id) : new ModelField(); if (info == null) { return(HandleResult.Error("无效数据")); } info.Init(); if (info.Id <= 0) { info.ModelNum = model.ModelNum; info.Name = model.Name; info.OptionType = model.OptionType; var oldInfo = await _modelFieldService.GetByName(model.Name, model.ModelNum); if (oldInfo != null && oldInfo.Id != info.Id) { return(HandleResult.Error("名称已存在")); } } info.Explain = model.Explain; info.Options = model.Options; var res = isUpdate ? await _modelFieldService.Update(info) : await _modelFieldService.Add(info); if (res.IsSuccess && !isUpdate) { await _modelFieldService.CreateField(info); } return(res); }
/// <summary> /// Post请求 /// </summary> /// <param name="modelFieldDto"></param> /// <param name="saveState"></param> public void HttpPostSave(ModelFieldDto modelFieldDto, SaveState saveState) { switch (saveState.OperationState) { case OperationState.Add: _modelFieldService.Add(modelFieldDto); break; case OperationState.Update: _modelFieldService.Update(modelFieldDto); break; default: break; } }