コード例 #1
0
        public PropertyFilterComponent(IAuditProperty <TProp> prop, TProp value, PropertyValueComparison comparison)
        {
            Property   = prop;
            Comparison = comparison;
            Value      = value;

            Expression <Func <AuditPropertyValue, bool> > valuePredicate;

            if (typeof(TProp) == typeof(string) && (comparison == PropertyValueComparison.Contains || comparison == PropertyValueComparison.NotContains))
            {
                var asStr = Convert.ToString(value);
                valuePredicate = comparison == PropertyValueComparison.Contains
                    ? Expr.Create(( AuditPropertyValue v ) => v.StringValue.Contains(asStr))
                    : Expr.Create(( AuditPropertyValue v ) => !v.StringValue.Contains(asStr));
            }
            else
            {
                var valueAccessor = AuditPropertyValue.GetAccessorExpression <TProp>();
                valuePredicate = Expression.Lambda <Func <AuditPropertyValue, bool> >(
                    Expression.MakeBinary(Op(Comparison), valueAccessor.Body, Expression.Constant(Value)),
                    valueAccessor.Parameters);
            }

            Filter = e => e.PropertyValues.Any(p => p.PropertyId == Property.ID && valuePredicate.Invoke(p));
            Filter = Filter.Expand();
        }
コード例 #2
0
        static ExpressionType Op(PropertyValueComparison c)
        {
            switch (c)
            {
            case PropertyValueComparison.Eq: return(ExpressionType.Equal);

            case PropertyValueComparison.Neq: return(ExpressionType.NotEqual);

            case PropertyValueComparison.Gt: return(ExpressionType.GreaterThan);

            case PropertyValueComparison.Gte: return(ExpressionType.GreaterThanOrEqual);

            case PropertyValueComparison.Lt: return(ExpressionType.LessThan);

            case PropertyValueComparison.Lte: return(ExpressionType.LessThanOrEqual);

            default: throw new NotSupportedException("Unsupported comparison type '" + c + "'");
            }
        }
コード例 #3
0
        public System.Web.WebPages.HelperResult Dropdowns(string id, IAuditProperty selectedProperty, PropertyValueComparison selectedComp)
        {
#line default
#line hidden
            return(new System.Web.WebPages.HelperResult(__razor_helper_writer => {
#line 89 "..\..\Views\PropertyFilterUI.cshtml"



#line default
#line hidden

#line 90 "..\..\Views\PropertyFilterUI.cshtml"
                WriteTo(__razor_helper_writer, Html.DropDownList("p" + id, Model.AllPossibleProperties.Select(x =>
                                                                                                              new SelectListItem {
                    Text = x.Name, Value = x.ID.ToString(), Selected = x == selectedProperty
                })
                                                                 .StartWith(new SelectListItem {
                    Selected = selectedProperty == null, Value = "", Text = "select property"
                }),
                                                                 new { @class = "Property" }));


#line default
#line hidden

#line 93 "..\..\Views\PropertyFilterUI.cshtml"



#line default
#line hidden

#line 94 "..\..\Views\PropertyFilterUI.cshtml"
                WriteTo(__razor_helper_writer, Html.DropDownList("c" + id, Enum.GetValues(typeof(PropertyValueComparison)).Cast <PropertyValueComparison>().Select(c =>
                                                                                                                                                                   new SelectListItem {
                    Text = c.ToString(), Value = c.ToString(), Selected = selectedComp == c
                }),
                                                                 new { @class = "Comparison", style = "display: none" }));


#line default
#line hidden

#line 96 "..\..\Views\PropertyFilterUI.cshtml"



#line default
#line hidden
            }));

#line 97 "..\..\Views\PropertyFilterUI.cshtml"
        }
コード例 #4
0
            public IPropertyFilter ParseComponent <TDomain>(ICompositionService comp, PropertyFilterFactory <TDomain> factory,
                                                            IPropertyFilter sourceFilter, IAuditProperty p, PropertyValueComparison cmp, string value)
            {
                var res = from prop in Maybe.Value(p as IAuditProperty <TProp>)
                          from selector in comp.Get <PropertyValueSelectorCache <TProp> >().GetSelector(prop)
                          from parsed in Maybe.SafeValue(() => selector.ParsePostedValue(value))

                          select sourceFilter == null?factory.Create(prop, parsed, cmp) : sourceFilter.And(prop, parsed, cmp);

                return(res.ValueOrNull() ?? sourceFilter);
            }
コード例 #5
0
 public static IPropertyFilter ParsePostedValue <TDomain>(ICompositionService comp, PropertyFilterFactory <TDomain> factory,
                                                          IPropertyFilter sourceFilter, IAuditProperty p, PropertyValueComparison cmp, string value)
 {
     return(HelperFor(p).ParseComponent(comp, factory, sourceFilter, p, cmp, value));
 }
コード例 #6
0
 public IPropertyFilter And <TProp>(IAuditProperty <TProp> prop, TProp value, PropertyValueComparison comparison)
 {
     return(new PropertyFilter(Components.Concat(new[] { new PropertyFilterComponent <TProp>(prop, value, comparison) }), Factory));
 }
コード例 #7
0
 public IPropertyFilter Create <TProp>(IAuditProperty <TProp> prop, TProp value, PropertyValueComparison comparison = PropertyValueComparison.Eq)
 {
     return(new PropertyFilter(new[] { new PropertyFilterComponent <TProp>(prop, value, comparison) }, this));
 }