示例#1
0
        public override async Task <EmbededViewResult> Execute()
        {
            Model = new ServiceMethodModel();

            var serviceName = this.HttpContext.Request.Query["_s"].ToString();
            var methodName  = this.HttpContext.Request.Query["_m"].ToString();

            Model.Service = _servicesService.GetService(serviceName);
            Model.Method  = Model.Service.Methods.FirstOrDefault(x => x.Id == methodName);

            var fieldsValues = new Dictionary <string, string>();

            if (IsPost())
            {
                fieldsValues = this.HttpContext.Request.Form
                               .Where(x => x.Key.StartsWith("_") == false && string.IsNullOrEmpty(x.Value.FirstOrDefault()) == false)
                               .ToDictionary(x => x.Key, x => x.Value.FirstOrDefault()?.ToString());
            }
            Model.FieldsWithValues = Model.Method.Method.GetParameters().Select(x => (x, fieldsValues.FirstOrDefault(v => v.Key == x.Name).Value)).ToList();

            if (IsSubmit())
            {
                var result = _servicesService.InvokeMethod(Model.Service, Model.Method, fieldsValues);
                Model.Errors          = result.Errors;
                Model.ExecutionResult = result.Result;
            }

            return(await View());
        }