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;
        }
Beispiel #2
0
        public static List <Signum.Entities.DynamicQuery.Filter> ExtractFilterOptions(HttpContextBase httpContext, QueryDescription queryDescription, bool canAggregate)
        {
            List <Signum.Entities.DynamicQuery.Filter> result = new List <Signum.Entities.DynamicQuery.Filter>();

            NameValueCollection parameters = httpContext.Request.Params;

            string field = parameters["filters"];

            if (!field.HasText())
            {
                return(result);
            }

            var matches = FindOptionsModelBinder.FilterRegex.Matches(field).Cast <Match>();

            return(matches.Select(m =>
            {
                string name = m.Groups["token"].Value;
                var token = QueryUtils.Parse(name, queryDescription, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement | (canAggregate ? SubTokensOptions.CanAggregate : 0));
                return new Signum.Entities.DynamicQuery.Filter(token,
                                                               EnumExtensions.ToEnum <FilterOperation>(m.Groups["op"].Value),
                                                               FindOptionsModelBinder.Convert(FindOptionsModelBinder.DecodeValue(m.Groups["value"].Value), token.Type));
            }).ToList());
        }
Beispiel #3
0
        public static List <Column> ExtractColumnsOptions(HttpContextBase httpContext, QueryDescription description, bool canAggregate)
        {
            List <Column> result = new List <Column>();

            NameValueCollection parameters = httpContext.Request.Params;
            string field = parameters["columns"];

            if (!field.HasText())
            {
                return(result);
            }

            var matches = FindOptionsModelBinder.ColumnRegex.Matches(field).Cast <Match>();

            return(matches.Select(m =>
            {
                var colName = m.Groups["token"].Value;
                string displayName = m.Groups["name"].Success ? FindOptionsModelBinder.DecodeValue(m.Groups["name"].Value) : null;

                var token = QueryUtils.Parse(colName, description, SubTokensOptions.CanElement | (canAggregate ? SubTokensOptions.CanAggregate : 0));

                return new Column(token, displayName ?? token.NiceName());
            }).ToList());
        }