public IActionResult Post([FromQuery] QueryArgs queryArgs, [FromBody] JObject jObj) { try { var json = jObj.ToString(); var bson = BsonDocument.Parse(json); if (bson == null || !bson.Any()) { return(JsonResultModel.Error("Parameter invalid:jObj = null 业务数据为空")); } //Pretreatment create queryContext QueryPiplineContext queryContext = PretreatmentAndCreateQueryPiplineContext(queryArgs); queryContext.MetaObject = metaObjectService.GetById(queryContext.MetaObjectId); if (queryContext.MetaObject == null) { return(JsonResultModel.Error($"未能找到对象Id为[{queryContext.MetaObjectId}]对应的对象信息")); } //缓存某个服务下的全部触发器脚本,包括before和after queryContext.TriggerScriptsOfOneServiceType = _triggerScriptService.GetTriggerScriptsUnDeletedByMetaObjectIdAndServiceType(queryContext.MetaObjectId, (int)ServiceType.Interface_Add); //trigger before bson = _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.Before, TriggerScriptService.FunctionName_MetaObject_Interface_Add_Before, bson, CurrentApplicationContext, queryContext.InterfaceCode, bson); //check data by form if (queryContext.FormId != default(int)) { var formCheckResult = _formMetaFieldService.ValidateFormData(queryContext.FormId, bson); if (!formCheckResult.IsSuccess) { return(formCheckResult.ToJsonResultModel()); } } //add data var addResult = dataAccessService.Add(queryContext.TenantId, queryContext.MetaObject, bson); //trigger after _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.After, TriggerScriptService.FunctionName_MetaObject_Interface_Add_After, bson, CurrentApplicationContext, queryContext.InterfaceCode, bson); return(addResult.ToJsonResultModel()); } catch (ArgumentNullException argNullEx) { return(JsonResultModel.Error(argNullEx.Message)); } catch (ArgumentException argEx) { return(JsonResultModel.Error(argEx.Message)); } catch (Exception ex) { return(JsonResultModel.Error(ex.Message)); } }
public IActionResult Post(string metaObjectCode, [FromBody] JObject jObj) { try { if (string.IsNullOrEmpty(metaObjectCode)) { return(JsonResultModel.Error($"Parameter invalid:metaObjectCode = null")); } if (jObj == null) { return(JsonResultModel.Error($"Parameter invalid:data = null")); } var json = jObj.ToString(); var bson = BsonDocument.Parse(json); //get metaObject var metaObject = metaObjectService.GetByCode(metaObjectCode); if (metaObject == null) { return(JsonResultModel.Error($"未能找到对象编码为[{metaObjectCode}]对应的对象信息")); } //trigger before bson = triggerScriptEngineService.AddBefore(metaObject.Id, metaObjectCode, bson); //add data var addResult = dataAccessService.Add(metaObject, bson); return(addResult.ToJsonResultModel()); } catch (Exception ex) { return(JsonResultModel.Error(ex.ToString())); } }