Esempio n. 1
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            FindOptions fo = new FindOptions();

            NameValueCollection parameters = controllerContext.HttpContext.Request.Params;

            if (parameters.AllKeys.Any(name => !name.HasText()))
            {
                throw new Exception("Incorrect URL: " + controllerContext.HttpContext.Request.Url.ToString());
            }

            object rawValue = bindingContext.ValueProvider.GetValue("webQueryName")?.RawValue;

            if (rawValue == null)
            {
                return(null);
            }

            string webQueryName = rawValue.GetType() == typeof(string[]) ? ((string[])rawValue)[0]: (string)rawValue;

            if (!webQueryName.HasText())
            {
                throw new InvalidOperationException("webQueryName not provided");
            }

            fo.QueryName = Finder.ResolveQueryName(webQueryName);

            QueryDescription queryDescription = DynamicQueryManager.Current.QueryDescription(fo.QueryName);

            fo.FilterOptions = ExtractFilterOptions(controllerContext.HttpContext, queryDescription);
            fo.OrderOptions  = ExtractOrderOptions(controllerContext.HttpContext, queryDescription);
            fo.ColumnOptions = ExtractColumnsOptions(controllerContext.HttpContext, queryDescription);

            if (parameters.AllKeys.Contains("allowSelection"))
            {
                bool aux;
                if (bool.TryParse(parameters["allowSelection"], out aux))
                {
                    fo.AllowSelection = aux;
                }
            }

            if (parameters.AllKeys.Contains("allowChangeColumns"))
            {
                fo.AllowChangeColumns = bool.Parse(parameters["allowChangeColumns"]);
            }

            if (parameters.AllKeys.Contains("allowOrder"))
            {
                fo.AllowOrder = bool.Parse(parameters["allowOrder"]);
            }

            if (parameters.AllKeys.Contains("showHeader"))
            {
                fo.ShowHeader = bool.Parse(parameters["showHeader"]);
            }

            if (parameters.AllKeys.Contains("showFilters"))
            {
                fo.ShowFilters = bool.Parse(parameters["showFilters"]);
            }

            if (parameters.AllKeys.Contains("showFilterButton"))
            {
                fo.ShowFilterButton = bool.Parse(parameters["showFilterButton"]);
            }

            if (parameters.AllKeys.Contains("showFooter"))
            {
                fo.ShowFooter = bool.Parse(parameters["showFooter"]);
            }

            if (parameters.AllKeys.Contains("showContextMenu"))
            {
                fo.ShowContextMenu = bool.Parse(parameters["showContextMenu"]);
            }

            if (parameters.AllKeys.Contains("columnMode"))
            {
                fo.ColumnOptionsMode = parameters["columnMode"].ToEnum <ColumnOptionsMode>();
            }

            if (parameters.AllKeys.Contains("create"))
            {
                fo.Create = bool.Parse(parameters["create"]);
            }

            if (parameters.AllKeys.Contains("navigate"))
            {
                fo.Navigate = bool.Parse(parameters["navigate"]);
            }

            if (parameters.AllKeys.Contains("pagination"))
            {
                switch (parameters["pagination"].ToEnum <PaginationMode>())
                {
                case PaginationMode.All:
                    fo.Pagination = new Pagination.All();
                    break;

                case PaginationMode.Firsts:
                    fo.Pagination = new Pagination.Firsts(int.Parse(parameters["elems"]));
                    break;

                case PaginationMode.Paginate:
                    fo.Pagination = new Pagination.Paginate(int.Parse(parameters["elems"]),
                                                            parameters.AllKeys.Contains("page") ? parameters["page"].ToInt() ?? 1 : 1);
                    break;

                default:
                    break;
                }
            }

            if (parameters.AllKeys.Contains("searchOnLoad"))
            {
                fo.SearchOnLoad = bool.Parse(parameters["searchOnLoad"]);
            }

            return(fo);
        }
Esempio n. 2
0
        public JObject ToJS(string prefix)
        {
            JObject op = new JObject()
            {
                { "prefix", prefix }
            };

            if (FilterOptions.Any())
            {
                QueryDescription queryDescription = DynamicQueryManager.Current.QueryDescription(QueryName);

                FilterOption.SetFilterTokens(this.FilterOptions, queryDescription, false);
            }

            if (QueryName != null)
            {
                op.Add("webQueryName", Finder.ResolveWebQueryName(QueryName));
            }
            if (SearchOnLoad == true)
            {
                op.Add("searchOnLoad", true);
            }
            if (!Navigate)
            {
                op.Add("navigate", false);
            }
            if (!Create)
            {
                op.Add("create", false);
            }
            if (!AllowSelection)
            {
                op.Add("allowSelection", false);
            }
            if (!SelectedItemsContextMenu)
            {
                op.Add("selectedItemsContextMenu", false);
            }
            if (!AllowChangeColumns)
            {
                op.Add("allowChangeColumns", false);
            }
            if (!AllowOrder)
            {
                op.Add("allowOrder", false);
            }
            if (!showHeader)
            {
                op.Add("showHeader", false);
            }
            if (!showFilters)
            {
                op.Add("showFilters", false);
            }
            if (!showFilterButton)
            {
                op.Add("showFilterButton", false);
            }
            if (!showFooter)
            {
                op.Add("showFooter", false);
            }
            if (!showContextMenu)
            {
                op.Add("showContextMenu", false);
            }
            if (FilterOptions.Any())
            {
                op.Add("filters", new JArray(filterOptions.Select(f => f.ToJS())));
            }
            if (OrderOptions.Any())
            {
                op.Add("orders", new JArray(OrderOptions.Select(oo => oo.ToJS())));
            }
            if (ColumnOptions.Any())
            {
                op.Add("columns", new JArray(ColumnOptions.Select(co => co.ToJS())));
            }
            if (ColumnOptionsMode != Entities.DynamicQuery.ColumnOptionsMode.Add)
            {
                op.Add("columnMode", ColumnOptionsMode.ToString());
            }

            if (Pagination != null)
            {
                op.Add("pagination", Pagination.GetMode().ToString());
                int?elems = Pagination.GetElementsPerPage();
                if (elems != null)
                {
                    op.Add("elems", elems.Value.ToString());
                }
            }

            return(op);
        }
Esempio n. 3
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            QueryRequest qr = new QueryRequest();

            NameValueCollection parameters = controllerContext.HttpContext.Request.Params;

            if (parameters.AllKeys.Any(name => !name.HasText()))
            {
                throw new Exception("Incorrect URL: " + controllerContext.HttpContext.Request.Url.ToString());
            }

            string webQueryName = "";
            object rawValue     = bindingContext.ValueProvider.GetValue("webQueryName")?.RawValue;

            if (rawValue.GetType() == typeof(string[]))
            {
                webQueryName = ((string[])rawValue)[0];
            }
            else
            {
                webQueryName = (string)rawValue;
            }

            if (!webQueryName.HasText())
            {
                throw new InvalidOperationException("webQueryName not provided");
            }

            qr.QueryName = Finder.ResolveQueryName(webQueryName);

            if (parameters.AllKeys.Contains("queryUrl"))
            {
                qr.QueryUrl = parameters["queryUrl"];
            }

            QueryDescription queryDescription = DynamicQueryManager.Current.QueryDescription(qr.QueryName);

            qr.Filters = ExtractFilterOptions(controllerContext.HttpContext, queryDescription, canAggregate: false);
            qr.Orders  = ExtractOrderOptions(controllerContext.HttpContext, queryDescription, canAggregate: false);
            qr.Columns = ExtractColumnsOptions(controllerContext.HttpContext, queryDescription, canAggregate: false);

            if (parameters.AllKeys.Contains("pagination"))
            {
                switch (parameters["pagination"].ToEnum <PaginationMode>())
                {
                case PaginationMode.All:
                    qr.Pagination = new Pagination.All();
                    break;

                case PaginationMode.Firsts:
                    qr.Pagination = new Pagination.Firsts(
                        parameters.AllKeys.Contains("elems") ? int.Parse(parameters["elems"]) : Pagination.Firsts.DefaultTopElements);
                    break;

                case PaginationMode.Paginate:
                    qr.Pagination = new Pagination.Paginate(
                        parameters.AllKeys.Contains("elems") ? int.Parse(parameters["elems"]) : Pagination.Paginate.DefaultElementsPerPage,
                        parameters.AllKeys.Contains("page") ? int.Parse(parameters["page"]) : 1);
                    break;

                default:
                    break;
                }
            }

            return(qr);
        }