Beispiel #1
0
        //public async Task<object> Path(string path, [FromQuery] MyQueryString query, [FromBody] Dictionary<string, object> model)
        public async Task <IActionResult> JimuPath(string path, [FromQuery] JimuQueryString query, [ModelBinder] JimuModel model)
        {
            var paras = new Dictionary <string, object>();

            if (model?.Data != null)
            {
                paras = model.Data;
            }
            if (query.Collection.Count > 0)
            {
                foreach (var key in query.Collection.Keys)
                {
                    paras[key] = query.Collection[key];
                }
            }
            if (!path.StartsWith("/"))
            {
                path = "/" + path;
            }
            var result = await JimuClient.Invoke($"{path}{(query.Query ?? "")}", paras, Request.Method);

            if (result?.ResultType != null && result.ResultType.StartsWith("{\"ReturnType\":\"Jimu.JimuRedirect\""))
            {
                var redirect = result.Result as JimuRedirect;
                return(Redirect(redirect.RedirectUrl));
            }
            //if (result.ResultType != typeof(JimuFile).ToString())
            if (result?.ResultType != null && result.ResultType.StartsWith("{\"ReturnType\":\"Jimu.JimuFile\""))
            {
                var file = result.Result as JimuFile;
                return(File(file?.Data, "application/octet-stream", file?.FileName));
            }
            //return new JsonResult(result.Result);
            return(Ok(result.Result));
        }
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
            var query       = bindingContext.ActionContext.HttpContext.Request.QueryString.Value;
            var queryString = new JimuQueryString(query);

            bindingContext.ModelState.SetModelValue("query", queryString, null);
            bindingContext.Result = ModelBindingResult.Success(queryString);
            return(Task.CompletedTask);
        }