/// <summary> /// 尝试根据方法的修饰属性来构造IActionResult实例 /// </summary> /// <param name="result"></param> /// <param name="format"></param> /// <returns></returns> private IActionResult ObjectToActionResult(object result, SerializeFormat format) { IActionResult actionResult = null; if (format == SerializeFormat.AUTO) { // 如果是自动响应,那么就根据请求头的指定的方式来决定 string expectFormat = this.HttpContext.Request.Headers["Result-Format"]; if (string.IsNullOrEmpty(expectFormat) == false) { SerializeFormat f2; if (Enum.TryParse <SerializeFormat>(expectFormat.ToUpper(), out f2)) { format = f2; } } } if (format == SerializeFormat.JSON) { actionResult = new JsonResult(result); } else if (format == SerializeFormat.JSON2) { actionResult = new JsonResult(result, true); } else if (format == SerializeFormat.XML) { actionResult = new XmlResult(result); } else if (format == SerializeFormat.FORM) { string text = FormDataProvider.Serialize(result).ToString(); actionResult = new TextResult(text); } // 无法构造出IActionResult实例,就按字符串形式输出 if (actionResult == null) { actionResult = new TextResult(result); } return(actionResult); }
// NOTE: we're not using the data view anymore. obsolete and can be removed. public IHttpActionResult GetDataView(Guid projectId, Guid formTemplateId) { var result = new List <List <string> >(); using (var provider = new FormDataProvider(formTemplateId, projectId, ignoreRepeaters: true)) { var dataTable = provider.GetDataTable(null, null); // Headers result.Add(dataTable.Columns.Cast <DataColumn>().Select(c => c.Caption).ToList()); foreach (DataRow row in dataTable.Rows) { result.Add(row.ItemArray.Select(v => v.ToString()).ToList()); } } return(Ok(result)); }