public Expression GetSingleFilterPredicateExpression( AdvancedFilterModel filter, ParameterExpression accessExpression) { var type = typeof(TEntity); var propertyType = type.GetProperty(filter.Column); var property = type.GetProperty(filter.Column); var propertyExpression = Expression.MakeMemberAccess(accessExpression, property ?? throw new InvalidOperationException()); if (propertyType == null) { throw new NullReferenceException(nameof(propertyType)); } var dateProperty = propertyType.PropertyType.GetProperty("Date"); if (dateProperty == null) { throw new NullReferenceException(nameof(dateProperty)); } var dateExpression = Expression.MakeMemberAccess(propertyExpression, dateProperty); var dateValue = DateTime.ParseExact(filter.Value, filter.DateFormat, CultureInfo.InvariantCulture); var dateAdditional = filter.AdditionalValue != null?DateTime.ParseExact(filter.AdditionalValue, filter.DateFormat, CultureInfo.InvariantCulture) : (DateTime?)null; var filterExpression = GetOperationExpression(filter, dateExpression, dateValue, dateAdditional); return(filterExpression); }
private static Expression GetOperationExpression( AdvancedFilterModel filter, Expression accessExpression, DateTime?value, DateTime?valueAdditional = null) { Expression predicate; var type = typeof(TEntity); var propertyType = type.GetProperty(filter.Column); Expression constant; Expression constantAdditional; if (Nullable.GetUnderlyingType(propertyType.PropertyType) != null) { constant = Expression.Convert(Expression.Constant(value != null ? value : (DateTime?)null), propertyType.PropertyType); constantAdditional = Expression.Convert( Expression.Constant(valueAdditional != null ? valueAdditional : (DateTime?)null), propertyType.PropertyType); } else { constant = Expression.Constant(value); constantAdditional = Expression.Constant(valueAdditional); } switch (filter.Operator) { case FilterOperator.Equals: predicate = Expression.Equal(accessExpression, constant); break; case FilterOperator.NotEquals: predicate = Expression.NotEqual(accessExpression, constant); break; case FilterOperator.GreaterThan: predicate = Expression.GreaterThanOrEqual(accessExpression, constant); break; case FilterOperator.LessThan: predicate = Expression.LessThanOrEqual(accessExpression, constant); break; case FilterOperator.Range: var predicateLess = Expression.GreaterThanOrEqual(accessExpression, constant); var predicateGreat = Expression.LessThanOrEqual(accessExpression, constantAdditional); predicate = Expression.And(predicateLess, predicateGreat); break; default: throw new ArgumentOutOfRangeException(); } return(predicate); }
public FilterPredicate GetPredicateExpression(IQueryable <TEntity> query, AdvancedFilterModel filter, ParameterExpression accessExpression) { var resultPredicate = GetSingleFilterPredicateExpression(filter, accessExpression); var filterPredicate = new FilterPredicate() { Predicate = resultPredicate, OperatorType = filter.FilterLinkCondition }; return(filterPredicate); }
public Expression GetSingleFilterPredicateExpression(AdvancedFilterModel filter, ParameterExpression accessExpression) { var type = typeof(TEntity); var property = type.GetProperty(filter.Column); if (property == null) { throw new NullReferenceException(nameof(property)); } var propertyExpression = Expression.MakeMemberAccess(accessExpression, property); Expression predicate; Expression aditionalPredicate = null; if (property.PropertyType.IsString()) { predicate = GetOperationExpression(filter.Operator, filter.Value, propertyExpression); if (filter.AdditionalOperator != FilterOperator.None && !string.IsNullOrEmpty(filter.AdditionalValue)) { aditionalPredicate = GetOperationExpression(filter.AdditionalOperator, filter.AdditionalValue, propertyExpression); } } else { var toString = type.GetMethod("ToString"); var stringExpression = Expression.Call(propertyExpression, toString ?? throw new InvalidOperationException()); predicate = GetOperationExpression(filter.AdditionalOperator, filter.AdditionalValue, stringExpression); if (filter.AdditionalOperator != FilterOperator.None && !string.IsNullOrEmpty(filter.AdditionalValue)) { aditionalPredicate = GetOperationExpression(filter.AdditionalOperator, filter.AdditionalValue, stringExpression); } } var resultPredicate = filter.Condition switch { FilterCondition.Or when aditionalPredicate != null => Expression.Or(predicate, aditionalPredicate), FilterCondition.And when aditionalPredicate != null => Expression.And(predicate, aditionalPredicate), FilterCondition.None => predicate, _ => throw new ArgumentOutOfRangeException() }; return(resultPredicate); }
public async Task <IActionResult> GetProfilerAsync([FromQuery] AdvancedFilterModel model) { var profilers = await easyProfilerContext.Get <Profiler>().ApplyFilter(model).Select(s => new ProfilerResponseDto { Duration = new TimeSpan(s.Duration), EndDate = s.EndDate, Id = s.Id, Query = s.Query, QueryType = s.QueryType, StartDate = s.StartDate, RequestUrl = s.RequestUrl }).ToListAsync(); return(Ok(profilers)); }
public Expression GetSingleFilterPredicateExpression(AdvancedFilterModel filter, ParameterExpression accessExpression) { var type = typeof(TEntity); var property = type.GetProperty(filter.Column); if (property == null) { throw new NullReferenceException(nameof(property)); } Expression predicate; Expression aditionalPredicate = null; if (property.PropertyType.IsBoolean()) { predicate = GetOperationExpression(filter.Operator, filter.Value, filter.Column, accessExpression); if (filter.AdditionalOperator != FilterOperator.None && !string.IsNullOrEmpty(filter.AdditionalValue)) { aditionalPredicate = GetOperationExpression( filter.AdditionalOperator, filter.AdditionalValue, filter.Column, accessExpression); } } else { throw new ArgumentOutOfRangeException($"The boolean filter over column {filter.Column} with value {filter.Value} can't be parsed"); } var resultPredicate = filter.Condition switch { FilterCondition.Or when aditionalPredicate != null => Expression.Or(predicate, aditionalPredicate), FilterCondition.And when aditionalPredicate != null => Expression.And(predicate, aditionalPredicate), FilterCondition.None => predicate, _ => throw new ArgumentOutOfRangeException() }; return(resultPredicate); }
private static Expression GetOperationExpression( AdvancedFilterModel filter, Expression accessExpression, DateTime value, DateTime?valueAdditional = null) { Expression predicate; switch (filter.Operator) { case FilterOperator.Equals: predicate = Expression.Equal(accessExpression, Expression.Constant(value)); break; case FilterOperator.NotEquals: predicate = Expression.NotEqual(accessExpression, Expression.Constant(value)); break; case FilterOperator.GreaterThan: predicate = Expression.GreaterThanOrEqual(accessExpression, Expression.Constant(value)); break; case FilterOperator.LessThan: predicate = Expression.LessThanOrEqual(accessExpression, Expression.Constant(value)); break; case FilterOperator.Range: var predicateLess = Expression.GreaterThanOrEqual(accessExpression, Expression.Constant(value)); var predicateGreat = Expression.LessThanOrEqual(accessExpression, Expression.Constant(valueAdditional)); predicate = Expression.And(predicateLess, predicateGreat); break; default: throw new ArgumentOutOfRangeException(); } return(predicate); }
/// <summary> /// Advanced filter. /// </summary> /// <param name="filterModel"> /// Filter object. /// </param> /// <returns> /// List of profiler. /// </returns> public async Task <List <Profiler> > AdvancedFilterAsync(AdvancedFilterModel filterModel) { return(await profilerDbContext.Profilers.ApplyFilter(filterModel).ToListAsync()); }
public async Task <IActionResult> AdvancedFilterForEasyProfilerAsync([FromQuery] AdvancedFilterModel model, [FromServices] IEasyProfilerBaseService <ProfilerPostgreSqlDbContext> baseService) { return(Ok(await baseService.AdvancedFilterAsync(model))); }
public async Task <List <Profiler> > AdvancedFilterAsync(AdvancedFilterModel advancedFilterModel) { return(await dbContext.Set <Profiler>().ApplyFilter(advancedFilterModel).ToListAsync()); }
public Task <List <Profiler> > AdvancedFilterAsync(AdvancedFilterModel advancedFilterModel) { return(Task.FromResult(easyProfilerContext.Profilers.AsQueryable().ApplyFilter(advancedFilterModel).ToList())); }
public async Task <IActionResult> AdvancedFilterForEasyProfilerAsync([FromQuery] AdvancedFilterModel model, [FromServices] IEasyProfilerService easyProfilerService) { return(Ok(await easyProfilerService.AdvancedFilterAsync(model))); }
/// <summary> /// Advanced filter. /// </summary> /// <param name="filterModel"> /// Filter object. /// </param> /// <returns> /// List of profiler. /// </returns> public async Task <List <Profiler> > AdvancedFilterAsync(AdvancedFilterModel filterModel, CancellationToken cancellationToken = default) { return(await profilerDbContext.Profilers.ApplyFilter(filterModel).ToListAsync(cancellationToken)); }
public void BindFilterSectionCollection() { #region Standard Filter actions // Make StatItemSection_IsActive depending on any FilterSectionItem is/not Checked StatItem.OnTriState = () => { SetStatItems(); }; StatItem.OnTriState.Invoke(); // Make StakeLevelSection_IsActive depending on any FilterSectionItem is/not Checked StakeLevelItem.OnIsChecked = () => { SetStakeLevelItems(); }; StakeLevelItem.OnIsChecked.Invoke(); BuyinItem.OnIsChecked = () => SetBuyinItems(); BuyinItem.OnIsChecked.Invoke(); // Make PreFlopActionSection_IsActive depending on any FilterSectionItem is/not Checked PreFlopActionItem.OnIsChecked = () => { SetPreFlopActionItems(); }; PreFlopActionItem.OnIsChecked.Invoke(); // Make CurrencySection_IsActive depending on any FilterSectionItem is/not Checked CurrencyItem.OnIsChecked = () => { SetCurrencyItems(); }; CurrencyItem.OnIsChecked.Invoke(); // Make TableRingSection_IsActive depending on any FilterSectionItem is/not Checked TableRingItem.OnIsChecked = () => { SetTableRingItems(); }; TableRingItem.OnIsChecked.Invoke(); FilterStandardModel.OnPlayersBetweenChanged = () => { SetPlayersBetweenItems(); }; FilterStandardModel.OnPlayersBetweenChanged.Invoke(); #endregion #region Hole Cards actions HoleCardsItem.OnIsChecked = () => { SetHoleCardsItems(); }; HoleCardsItem.OnIsChecked.Invoke(); #endregion #region Date Filter Actions FilterDateModel.OnChanged = () => { SetDateItems(); }; FilterDateModel.OnChanged.Invoke(); #endregion #region Hand Values actions FastFilterItem.OnTriState = () => { SetHandValueFastFilterItems(); }; FastFilterItem.OnTriState.Invoke(); HandValueItem.OnIsChecked = (street) => { SetHandValueItems(street); }; HandValueItem.OnIsChecked.Invoke(Street.Flop); HandValueItem.OnIsChecked.Invoke(Street.Turn); HandValueItem.OnIsChecked.Invoke(Street.River); #endregion #region Board Texture actions BoardCardItem.OnChanged = (street) => { SetBoardCardItems(street); }; BoardTextureItem.OnChanged = (street) => { SetBoardTextureItems(street); }; BoardCardItem.OnChanged.Invoke(Street.Flop); BoardCardItem.OnChanged.Invoke(Street.Turn); BoardCardItem.OnChanged.Invoke(Street.River); BoardTextureItem.OnChanged.Invoke(Street.Flop); BoardTextureItem.OnChanged.Invoke(Street.Turn); BoardTextureItem.OnChanged.Invoke(Street.River); #endregion #region HandAction Filter actions HandActionFilterItem.OnChanged = (street) => { SetHandActionItems(street); }; HandActionFilterItem.OnChanged.Invoke(Street.Preflop); HandActionFilterItem.OnChanged.Invoke(Street.Flop); HandActionFilterItem.OnChanged.Invoke(Street.Turn); HandActionFilterItem.OnChanged.Invoke(Street.River); #endregion #region Omaha Hand Grid Actions OmahaHandGridItem.OnChanged = () => { SetOmahaHandGridItems(); }; OmahaHandGridItem.OnChanged.Invoke(); #endregion #region Quick Filter actions QuickFilterItem.OnTriState = () => { SetQuickFilterItems(); }; QuickFilterItem.OnTriState.Invoke(); #endregion #region Advanced Filter AdvancedFilterModel?.SetBuiltFilterModel(this); #endregion }
public Expression GetSingleFilterPredicateExpression(AdvancedFilterModel filter, ParameterExpression accessExpression) { var predicate = FilterBooleanByFunction(filter.Column, filter.Value, accessExpression); return(predicate); }
private Expression GetOperationExpression(FilterOperator filterOperator, int value, string propertyName, ParameterExpression accessExpression, AdvancedFilterModel filter) { var type = typeof(TEntity); var property = type.GetProperty(propertyName); if (property == null) { throw new NullReferenceException(nameof(property)); } var mytype = property.PropertyType.ToString() switch { "System.Nullable`1[System.Int16]" => typeof(int), "System.Nullable`1[System.Int32]" => typeof(int), "System.Nullable`1[System.Int64]" => typeof(int), "System.Nullable`1[System.Decimal]" => typeof(decimal), "System.Nullable`1[System.Double]" => typeof(double), "System.Nullable`1[System.Float]" => typeof(float), _ => throw new ArgumentOutOfRangeException() }; var propertyExpression = Expression.MakeMemberAccess(accessExpression, property); var left = Expression.Convert(propertyExpression, mytype); var right = Expression.Constant(value); var predicate = filterOperator switch { FilterOperator.Equals => Expression.Equal(left, right), FilterOperator.NotEquals => Expression.NotEqual(left, right), FilterOperator.GreaterThan => Expression.GreaterThan(left, right), FilterOperator.LessThan => Expression.LessThan(left, right), _ => throw new ArgumentOutOfRangeException() }; return(predicate); } } }