public ActionResult VisualList(DataSourceRequest command, string searchValues, IEnumerable <Sort> sort = null)
        {
            var model = BuildVisualSearchModel();

            if (ModelState.IsValid)
            {
                model.Update(searchValues);

                PagedResult <Visual> data = _visualService.GetVisuals(model.ToExpression(this._workContext.CurrentUser.Id), model.ToParameters(), command.Page - 1, command.PageSize, sort);
                var result = data.Result.Select(x => x.ToModel()).ToList();
                foreach (var r in result)
                {
                    r.VisualTypeText = r.VisualType.ToString();
                }
                var gridModel = new DataSourceResult
                {
                    Data  = result,
                    Total = data.TotalCount
                };
                return(new JsonResult
                {
                    Data = gridModel
                });
            }

            return(Json(new { Errors = ModelState.SerializeErrors() }));
        }
        public ActionResult List(DataSourceRequest command, string searchValues, IEnumerable <Sort> sort = null)
        {
            var model = _httpContext.Session[SessionKey.VisualSearchModel] as SearchModel;

            if (model == null)
            {
                model = BuildSearchModel();
            }
            else
            {
                model.ClearValues();
            }
            //validate
            var errorFilters = model.Validate(searchValues);

            foreach (var filter in errorFilters)
            {
                ModelState.AddModelError(filter.Name, _localizationService.GetResource(filter.ResourceKey + ".Required"));
            }
            if (ModelState.IsValid)
            {
                //session update
                model.Update(searchValues);
                _httpContext.Session[SessionKey.VisualSearchModel] = model;

                PagedResult <Visual> data = _visualService.GetVisuals(model.ToExpression(this._workContext.CurrentUser.Id), model.ToParameters(), command.Page - 1, command.PageSize, sort);
                var result = data.Result.Select(x => x.ToModel()).ToList();
                foreach (var r in result)
                {
                    r.VisualTypeText = r.VisualType.ToString();
                }

                var gridModel = new DataSourceResult
                {
                    Data  = result,
                    Total = data.TotalCount
                };
                return(new JsonResult
                {
                    Data = gridModel
                });
            }

            return(Json(new { Errors = ModelState.SerializeErrors() }));
        }