protected virtual ActionResult CreateActionResult(object model)
 {
     return(resultFactory.Create(model));
 }
Example #2
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (!filterContext.HttpContext.Request.IsAjaxRequest())
            {
                return;
            }

            var actionResultAdapter = adapterFactory.Create(filterContext.Result);

            if (actionResultAdapter == null)
            {
                return;
            }

            var dataSource = actionResultAdapter.GetDataSource();

            if (dataSource == null)
            {
                return;
            }

            var total = actionResultAdapter.GetTotal();

            var dataProcessor = new GridDataProcessor(new GridActionBindingContext(EnableCustomBinding, filterContext.Controller, dataSource, total));

            var result = new Dictionary <string, object>();
            var dataTableEnumerable = dataSource as GridDataTableWrapper;

            if (dataTableEnumerable != null && dataTableEnumerable.Table != null)
            {
                result["data"] = dataProcessor.ProcessedDataSource.SerializeToDictionary(dataTableEnumerable.Table);
            }
            else
            {
                result["data"] = dataProcessor.ProcessedDataSource;
            }

            result["total"] = dataProcessor.Total;

            var modelState = actionResultAdapter.GetModelState();

            if (modelState != null && !modelState.IsValid)
            {
                result["modelState"] = SerializeErrors(modelState);
            }

            if (EnableCustomBinding)
            {
                var aggregates = actionResultAdapter.GetAggregates();
                if (aggregates != null)
                {
                    result["aggregates"] = aggregates;
                }
            }
            else
            {
                SerializeAggregateResults(result, dataProcessor.AggregatesResults);
            }

            filterContext.Result = resultFactory.Create(result);
        }