Example #1
0
        protected internal virtual ActionResult SimpleFilterBuilderResult(ControllerBase controller, List <FilterOption> filterOptions)
        {
            object queryName = Finder.ResolveQueryName(controller.ParseValue <string>("webQueryName"));

            var qd = DynamicQueryManager.Current.QueryDescription(queryName);

            FilterOption.SetFilterTokens(filterOptions, qd, canAggregate: false);

            if (controller.ParseValue <bool>("returnHtml"))
            {
                controller.ViewData.Model = new Context(null, controller.Prefix());
                controller.ViewData[ViewDataKeys.FilterOptions] = filterOptions;

                return(new PartialViewResult
                {
                    ViewName = FilterRowsView,
                    ViewData = controller.ViewData,
                });
            }
            else
            {
                return(new ContentResult
                {
                    Content = filterOptions.ToString(";")
                });
            }
        }
        public static void PostConstructors_AddFilterProperties(ConstructorContext ctx, ModifiableEntity entity)
        {
            HttpContextBase httpContext = ctx.Controller.ControllerContext.HttpContext;

            if (!httpContext.Request.Params.AllKeys.Contains("webQueryName"))
            {
                return;
            }

            if (!(entity is Entity))
            {
                return;
            }

            object queryName = Finder.ResolveQueryName(httpContext.Request.Params["webQueryName"]);

            if (entity.GetType() != queryName as Type)
            {
                return;
            }

            QueryDescription queryDescription = DynamicQueryManager.Current.QueryDescription(queryName);

            var filters = FindOptionsModelBinder.ExtractFilterOptions(httpContext, queryDescription)
                          .Where(fo => fo.Operation == FilterOperation.EqualTo);

            var pairs = from pi in ctx.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                        join fo in filters on pi.Name equals fo.Token.Key
                        //where CanConvert(fo.Value, pi.PropertyType) && fo.Value != null
                        where fo.Value != null
                        select new { pi, fo };

            foreach (var p in pairs)
            {
                p.pi.SetValue(entity, Common.Convert(p.fo.Value, p.pi.PropertyType), null);
            }

            return;
        }
Example #3
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);
        }
Example #4
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);
        }