private static ExpressionStarter <CampaignEntity> GetMultipleStatusesFilter(IEnumerable <CampaignStatus> stats, ExpressionStarter <CampaignEntity> innerPredicate) { var currentDate = DateTime.UtcNow; foreach (var status in stats) { switch (status) { case CampaignStatus.Pending: innerPredicate = innerPredicate.Or(IsPendingCampaign(currentDate).And(c => c.IsEnabled)); break; case CampaignStatus.Active: innerPredicate = innerPredicate.Or(IsActiveCampaign(currentDate).And(c => c.IsEnabled)); break; case CampaignStatus.Completed: innerPredicate = innerPredicate.Or(IsCompletedCampaign(currentDate).And(c => c.IsEnabled)); break; case CampaignStatus.Inactive: innerPredicate = innerPredicate.Or(IsInactiveCampaign()); break; } } return(innerPredicate); }
/// <summary> /// Returns a predicate to filter the data by based on the keywords supplied /// </summary> /// <param name="keywords">Keywords to filter by</param> /// <returns>An expression to use for filtering</returns> protected override ExpressionStarter <Employee> BuildSearchFilterPredicate(string[] keywords) { Expression <Func <Employee, bool> > filterExpression = a => true; ExpressionStarter <Employee> predicate = PredicateBuilder.New(filterExpression); bool isFilteredQuery = keywords.Any(); if (!isFilteredQuery) { return(predicate); } predicate = filterExpression = a => false; foreach (var keyword in keywords) { var temp = keyword; if (temp == null) { continue; } predicate = predicate.Or(p => p.FirstName.ToLower().Contains(temp.ToLower())); predicate = predicate.Or(p => p.LastName.ToLower().Contains(temp.ToLower())); predicate = predicate.Or(p => p.Title.ToLower().Contains(temp.ToLower())); } return(predicate); }
public static ExpressionStarter <ResCurrentType> Build(ResourceSearch <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> NewPredicate, SearchParameterBase SearchItem) { if (SearchItem is SearchParameterToken) { var SearchTypeToken = SearchItem as SearchParameterToken; foreach (var SearchValue in SearchTypeToken.ValueList) { if (!SearchTypeToken.Modifier.HasValue) { NewPredicate = CollectionEqualToPredicate(Search, NewPredicate, SearchTypeToken, SearchValue); } else { switch (SearchTypeToken.Modifier) { case SearchParameter.SearchModifierCode.Missing: if (SearchValue.IsMissing) { NewPredicate = NewPredicate.Or(Search.SearchParameterIsNull <ResIndexTokenType>(SearchTypeToken.Id)); } else { NewPredicate = NewPredicate.Or(Search.SearchParameterIdIsNotNull <ResIndexTokenType>(SearchTypeToken.Id)); } break; case SearchParameter.SearchModifierCode.Exact: throw new FormatException($"The search modifier: {SearchTypeToken.Modifier.ToString()} is not supported for search parameter types of Token."); case SearchParameter.SearchModifierCode.Contains: throw new FormatException($"The search modifier: {SearchTypeToken.Modifier.ToString()} is not supported for search parameter types of Token."); case SearchParameter.SearchModifierCode.Text: throw new FormatException($"The search modifier: {SearchTypeToken.Modifier.ToString()} is not supported for search parameter types of Token."); case SearchParameter.SearchModifierCode.Type: throw new FormatException($"The search modifier: {SearchTypeToken.Modifier.ToString()} is not supported for search parameter types of Token."); case SearchParameter.SearchModifierCode.Below: throw new FormatException($"The search modifier: {SearchTypeToken.Modifier.ToString()} is not supported for search parameter types of Token."); case SearchParameter.SearchModifierCode.Above: throw new FormatException($"The search modifier: {SearchTypeToken.Modifier.ToString()} is not supported for search parameter types of Token."); case SearchParameter.SearchModifierCode.In: throw new FormatException($"The search modifier: {SearchTypeToken.Modifier.ToString()} is not supported for search parameter types of Token."); case SearchParameter.SearchModifierCode.NotIn: throw new FormatException($"The search modifier: {SearchTypeToken.Modifier.ToString()} is not supported for search parameter types of Token."); default: throw new System.ComponentModel.InvalidEnumArgumentException(SearchTypeToken.Modifier.ToString(), (int)SearchTypeToken.Modifier, typeof(SearchParameter.SearchModifierCode)); } } } } return(NewPredicate); }
private static ExpressionStarter <IResourceIndexed> CollectionNotEqualToPredicate(Search <IResourceIndexed> Search, ExpressionStarter <IResourceIndexed> NewPredicate, SearchParameterDateTime SearchTypeDateTime, SearchParameterDateTimeValue SearchValue) { var NotEqualToExpression = Search.DateTimePeriodCollectionAnyNotEqualTo(SearchTypeDateTime.Id, SearchValue.Value, FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision)); var CollectionIsNullExpression = Search.SearchParameterIsNull <Index.IDateTimeIndex>(SearchTypeDateTime.Id); NewPredicate = NewPredicate.Or(NotEqualToExpression); NewPredicate = NewPredicate.Or(CollectionIsNullExpression); return(NewPredicate); }
private static ExpressionStarter <ResCurrentType> CollectionNotEqualToPredicate(ResourceSearchExpressionTrees <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> NewPredicate, SearchParameterDateTime SearchTypeDateTime, SearchParameterDateTimeValue SearchValue) { var NotEqualToExpression = Search.DateTimePeriodCollectionAnyNotEqualTo(SearchTypeDateTime.Id, SearchValue.Value, FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision)); var CollectionIsNullExpression = Search.SearchParameterIsNull <ResIndexDateTimeType>(SearchTypeDateTime.Id); NewPredicate = NewPredicate.Or(NotEqualToExpression); NewPredicate = NewPredicate.Or(CollectionIsNullExpression); return(NewPredicate); }
public override ExpressionStarter <Empresa> ConfigureFilter(ExpressionStarter <Empresa> predicate, string searchValue) { if (!string.IsNullOrEmpty(searchValue)) { searchValue = searchValue.ToUpper(); predicate = predicate.Or(e => e.RazaoSocial.ToUpper().Contains(searchValue)); predicate = predicate.Or(e => e.NomeFantasia.ToUpper().Contains(searchValue)); predicate = predicate.Or(e => e.CGC.ToUpper().Contains(searchValue)); } return(predicate); }
private static void IdSearchParameterPredicateProcessing(List <ISearchParameterBase> SearchParametersList, ResourceSearchExpressionTrees <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> MainPredicate) { var IdSearchParamerterList = SearchParametersList.Where(x => x.Resource == FHIRAllTypes.Resource.GetLiteral() && x.Name == "_id"); if (IdSearchParamerterList != null) { ExpressionStarter <ResCurrentType> NewIdPredicate = null; foreach (var IdSearchParameter in IdSearchParamerterList) { if (IdSearchParameter is SearchParameterToken SearchTypeToken) { NewIdPredicate = LinqKit.PredicateBuilder.New <ResCurrentType>(); foreach (var SearchValue in SearchTypeToken.ValueList) { if (!SearchTypeToken.Modifier.HasValue) { var Expression = Search.MainResourceFhirIdAny(SearchValue.Code); NewIdPredicate = NewIdPredicate.Or(Expression); } } } MainPredicate.Extend <ResCurrentType>(NewIdPredicate, PredicateOperator.And); } SearchParametersList.RemoveAll(x => x.Resource == FHIRAllTypes.Resource.GetLiteral() && x.Name == "_id"); } }
public ResultHandler <Expression <Func <EventModel, bool> > > BuildExpression(FilterStatement <EventModel> filterStatement) { try { ExpressionStarter <EventModel> result = PredicateBuilder.New <EventModel>(); switch (filterStatement.PropertyName) { case "Audience": var values = JsonConvert.DeserializeObject <IEnumerable <int> >(filterStatement.ValueJson); foreach (var value in values) { result.Or(x => x.Audience == value); } break; default: throw new NotImplementedException("No filter support for this property"); } return(ResultHandler.Ok <Expression <Func <EventModel, bool> > >(result)); } catch (Exception ex) { this._logger.LogError(ex, "MultiCheckboxFilter.BuildExpression Failure"); return(ResultHandler.Fail <Expression <Func <EventModel, bool> > >(ex)); } }
private static ExpressionStarter <ResCurrentType> CollectionEqualToPredicate(ResourceSearchExpressionTrees <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> NewPredicate, SearchParameterNumber SearchTypeNumber, SearchParameterNumberValue SearchValue) { var Expression = Search.NumberCollectionAnyEqualTo(SearchTypeNumber.Id, Common.Tools.DecimalSupport.CalculateLowNumber(SearchValue.Value, SearchValue.Scale), SearchValue.Value, Common.Tools.DecimalSupport.CalculateHighNumber(SearchValue.Value, SearchValue.Scale)); NewPredicate = NewPredicate.Or(Expression); return(NewPredicate); }
private static ExpressionStarter <IResourceIndexed> CollectionEqualToPredicate(Search <IResourceIndexed> Search, ExpressionStarter <IResourceIndexed> NewPredicate, SearchParameterNumber SearchTypeNumber, SearchParameterNumberValue SearchValue) { var Expression = Search.NumberCollectionAnyEqualTo(SearchTypeNumber.Id, Common.Tools.DecimalSupport.CalculateLowNumber(SearchValue.Value, SearchValue.Scale), SearchValue.Value, Common.Tools.DecimalSupport.CalculateHighNumber(SearchValue.Value, SearchValue.Scale)); NewPredicate = NewPredicate.Or(Expression); return(NewPredicate); }
private static ExpressionStarter <IResourceIndexed> CollectionEqualToPredicate(Search <IResourceIndexed> Search, ExpressionStarter <IResourceIndexed> NewPredicate, SearchParameterToken SearchTypeToken, SearchParameterTokenValue SearchValue) { var Expression = Search.TokenCollectionAnyEqualTo(SearchTypeToken.Id, SearchValue.Code, SearchValue.System, SearchValue.SearchType); NewPredicate = NewPredicate.Or(Expression); return(NewPredicate); }
public Task <IEnumerable <PublishedProviderResult> > GetPublishedProviderResultsForSpecificationAndStatus(string specificationId, UpdatePublishedAllocationLineResultStatusModel filterCriteria) { IQueryable <PublishedProviderResult> results = _cosmosRepository.Query <PublishedProviderResult>(enableCrossPartitionQuery: true).Where(m => m.SpecificationId == specificationId && m.FundingStreamResult.AllocationLineResult.Current.Status == filterCriteria.Status); ExpressionStarter <PublishedProviderResult> providerPredicate = PredicateBuilder.New <PublishedProviderResult>(false); foreach (UpdatePublishedAllocationLineResultStatusProviderModel provider in filterCriteria.Providers) { string providerId = provider.ProviderId; providerPredicate = providerPredicate.Or(p => p.ProviderId == providerId); ExpressionStarter <PublishedProviderResult> allocationLinePredicate = PredicateBuilder.New <PublishedProviderResult>(false); foreach (string allocationLineId in provider.AllocationLineIds) { string temp = allocationLineId; allocationLinePredicate = allocationLinePredicate.Or(a => a.FundingStreamResult.AllocationLineResult.AllocationLine.Id == temp); } providerPredicate = providerPredicate.And(allocationLinePredicate); } results = results.AsExpandable().Where(providerPredicate); List <PublishedProviderResult> result = new List <PublishedProviderResult>(results); return(Task.FromResult(result.AsEnumerable())); }
private static ExpressionStarter <ResCurrentType> CollectionEqualToPredicate(ResourceSearch <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> NewPredicate, SearchParameterToken SearchTypeToken, SearchParameterTokenValue SearchValue) { var Expression = Search.TokenCollectionAnyEqualTo(SearchTypeToken.Id, SearchValue.Code, SearchValue.System, SearchValue.SearchType); NewPredicate = NewPredicate.Or(Expression); return(NewPredicate); }
private static ExpressionStarter <T> HandleDate <T>(ExpressionStarter <T> predicate, object value, string domainName, PropertyComparisonTypeEnum propertyComparison, ExpressionCombinationTypeEnum expressionCombination, Type type) { if (value == null) { return(predicate); } if (CheckIfDefaultValue(value, type)) { return(predicate); } Expression <Func <T, bool> > condition = GetExpression <T>(propertyComparison, value, domainName); switch (expressionCombination) { case ExpressionCombinationTypeEnum.And: predicate.And(condition); break; case ExpressionCombinationTypeEnum.Or: predicate.Or(condition); break; default: predicate.And(condition); break; } return(predicate); }
private static ExpressionStarter <ResCurrentType> CollectionEqualToPredicate(ResourceSearchExpressionTrees <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> NewPredicate, SearchParameterComposite SearchTypeComposite, SearchParameterCompositeValue SearchValue, IPrimaryServiceRootCache IPrimaryServiceRootCache) { var _ResourceSearch = new ResourceSearch <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType>(IPrimaryServiceRootCache); var Expression = _ResourceSearch.ANDSearchParameterListPredicateGenerator(SearchValue.SearchParameterBaseList); NewPredicate = NewPredicate.Or(Expression); return(NewPredicate); }
public Expression <Func <Channel, bool> > GetChannelExpression(string query) { ExpressionStarter <Channel> chatCondition = PredicateBuilder.New <Channel>(); string lowerQuery = query.ToLowerInvariant(); chatCondition = chatCondition.Or(chat => chat.SearchVector.Matches(EF.Functions.PhraseToTsQuery("simple", query))); return((Expression <Func <Channel, bool> >)chatCondition.Expand()); }
private static ExpressionStarter <ResCurrentType> Equals(ResourceSearch <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> NewLastUpdatedPredicate, SearchParameterDateTimeValue SearchValue) { var ExpressionLow = Search.LastUpdatedPropertyGreaterThanOrEqualTo(SearchValue.Value); var ExpressionHigh = Search.LastUpdatedPropertyLessThanOrEqualTo(FhirDateTimeSupport.CalculateHighDateTimeForRange(SearchValue.Value, SearchValue.Precision)); var Expression = ExpressionLow.And(ExpressionHigh); NewLastUpdatedPredicate = NewLastUpdatedPredicate.Or(Expression); return(NewLastUpdatedPredicate); }
public LinqQuery <TEntity> Or(Expression <Func <TEntity, bool> > expression) { if (expression != null) { hasPredicate = true; predicate = predicate.Or(expression); } return(this); }
/// <summary> /// Gets the value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="p">The p.</param> /// <param name="predicate">The predicate.</param> /// <param name="searchValue"></param> private void GetPredicate <T>(DataTablesColumnModel p, ExpressionStarter <T> predicate, string searchValue) { // PropertyInfo pi = typeof(T).GetProperty(p.Data); var exp = BuildExpression <T>(searchValue, p.Data); if (exp != null) { predicate.Or(exp); } }
public Expression <Func <User, bool> > GetUserExpression(string query) { ExpressionStarter <User> userCondition = PredicateBuilder.New <User>(); string lowerQuery = query.ToLowerInvariant(); userCondition = userCondition.Or(user => user.Phones.Any(opt => opt.PhoneNumber == query) || user.Emails.Any(opt => opt.EmailAddress.ToLower() == query.ToLowerInvariant()) || user.SearchVector.Matches(EF.Functions.PhraseToTsQuery("simple", query))); return((Expression <Func <User, bool> >)userCondition.Expand()); }
private string GetOtherVersesTranslation(Session session, int numberOfBook, int numberOfChapter, int verseStart, int verseEnd) { IEnumerable <Verse> verses = null; ExpressionStarter <Verse> predicate = null; if (numberOfBook > 460) { predicate = PredicateBuilder.New <Verse>(); for (int i = verseStart; i < verseEnd + 1; i++) { var index = $"PBPW.{numberOfBook}.{numberOfChapter}.{i}"; predicate = predicate.Or(x => x.Index == index); } verses = new XPQuery <Verse>(session).Where(predicate); } else { predicate = PredicateBuilder.New <Verse>(); for (int i = verseStart; i < verseEnd + 1; i++) { var index = $"SNP18.{numberOfBook}.{numberOfChapter}.{i}"; predicate = predicate.Or(x => x.Index == index); } verses = new XPQuery <Verse>(session).Where(predicate); } if (verses.Count() > 0) { var versesText = String.Empty; foreach (var item in verses) { versesText += item.Text + " "; } versesText = System.Text.RegularExpressions.Regex.Replace(versesText, @"\[[0-9]+\]", ""); return(versesText.Trim()); } return(String.Empty); }
private static ExpressionStarter <ResCurrentType> CollectionNotEqualToPredicate(ResourceSearchExpressionTrees <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> NewPredicate, SearchParameterNumber SearchTypeNumber, SearchParameterNumberValue SearchValue) { var NotEqualToExpression = Search.NumberCollectionAllNotEqualTo(SearchTypeNumber.Id, Common.Tools.DecimalSupport.CalculateLowNumber(SearchValue.Value, SearchValue.Scale), SearchValue.Value, Common.Tools.DecimalSupport.CalculateHighNumber(SearchValue.Value, SearchValue.Scale)); var CollectionNotNull_Expression = Search.SearchParameterIdIsNotNull <ResIndexQuantityType>(SearchTypeNumber.Id); ExpressionStarter <ResCurrentType> NewAndPredicate = LinqKit.PredicateBuilder.New <ResCurrentType>(); NewAndPredicate = NewAndPredicate.And(NotEqualToExpression); NewAndPredicate = NewAndPredicate.And(CollectionNotNull_Expression); NewPredicate = NewPredicate.Or(NewAndPredicate); return(NewPredicate); }
private static ExpressionStarter <IResourceIndexed> CollectionNotEqualToPredicate(Search <IResourceIndexed> Search, ExpressionStarter <IResourceIndexed> NewPredicate, SearchParameterNumber SearchTypeNumber, SearchParameterNumberValue SearchValue) { var NotEqualToExpression = Search.NumberCollectionAllNotEqualTo(SearchTypeNumber.Id, Common.Tools.DecimalSupport.CalculateLowNumber(SearchValue.Value, SearchValue.Scale), SearchValue.Value, Common.Tools.DecimalSupport.CalculateHighNumber(SearchValue.Value, SearchValue.Scale)); var CollectionNotNull_Expression = Search.SearchParameterIdIsNotNull <Index.IQuantityIndex>(SearchTypeNumber.Id); ExpressionStarter <IResourceIndexed> NewAndPredicate = LinqKit.PredicateBuilder.New <IResourceIndexed>(); NewAndPredicate = NewAndPredicate.And(NotEqualToExpression); NewAndPredicate = NewAndPredicate.And(CollectionNotNull_Expression); NewPredicate = NewPredicate.Or(NewAndPredicate); return(NewPredicate); }
private async Task <Expression <Func <IndexReference, bool> > > ChainRecursion2(AppDbContext AppDbContext, Expression <Func <IndexReference, bool> > OtherIndexRefQuery, ISearchQueryBase ChainSearchQuery) { if (ChainSearchQuery.ChainedSearchParameter.ChainedSearchParameter is null) { switch (ChainSearchQuery.ChainedSearchParameter.SearchParamTypeId) { case Common.Enums.SearchParamType.String: List <Expression <Func <IndexString, bool> > > PredicateList = IResourceStorePredicateFactory.StringIndex(ChainSearchQuery.ChainedSearchParameter); IQueryable <IndexString> IndexString = AppDbContext.Set <IndexString>(); ExpressionStarter <IndexString> PredicateGus = PredicateBuilder.New <IndexString>(true); foreach (var Pred in PredicateList) { Expression <Func <IndexString, bool> > Temp = Pred; PredicateGus = PredicateGus.Or(Temp); } OtherIndexRefQuery = OtherIndexRefQuery.And(x => x.SearchParameterId == 1 & x.ResourceTypeId == ChainSearchQuery.TypeModifierResource !.Value & x.SearchParameterId == ChainSearchQuery.Id & x.VersionId == null & x.CanonicalVersionId == null & x.ResourceStore.ContainedId == null & IndexString.Where(PredicateGus).Select(ss => ss.ResourceStore.ResourceId).Contains(x.ResourceId)); return(OtherIndexRefQuery); default: throw new NotImplementedException(); } } else { ExpressionStarter <IndexReference> Resultx = await ChainRecursion2(AppDbContext, OtherIndexRefQuery, ChainSearchQuery.ChainedSearchParameter); IQueryable <IndexReference> IndexReference = AppDbContext.Set <IndexReference>(); OtherIndexRefQuery = OtherIndexRefQuery.And(x => x.SearchParameterId == 1 & x.ResourceTypeId == ChainSearchQuery.TypeModifierResource !.Value & x.SearchParameterId == ChainSearchQuery.Id & x.VersionId == null & x.CanonicalVersionId == null & x.ResourceStore.ContainedId == null & IndexReference.Where(Resultx).Select(ss => ss.ResourceStore.ResourceId).Contains(x.ResourceId)); return(OtherIndexRefQuery); } }
public static ExpressionStarter <T> PredicateByOperationType <T>(this ExpressionStarter <T> predicate, BitwiseOperation operation, Expression <Func <T, bool> > expr) { switch (operation) { case BitwiseOperation.And: predicate = predicate.And(expr); break; case BitwiseOperation.Or: predicate = predicate.Or(expr); break; } return(predicate); }
public override ExpressionStarter <Pessoa> ConfigureFilter(ExpressionStarter <Pessoa> predicate, string searchValue) { if (!string.IsNullOrEmpty(searchValue)) { searchValue = searchValue.ToUpper(); predicate = predicate.Or(e => e.Nome.ToUpper().Contains(searchValue)); predicate = predicate.Or(e => e.NomeCompleto.ToUpper().Contains(searchValue)); predicate = predicate.Or(e => e.CPF.ToUpper().Contains(searchValue)); predicate = predicate.Or(e => e.RG.ToUpper().Contains(searchValue)); predicate = predicate.Or(e => e.TelefoneEmergencia.ToUpper().Contains(searchValue)); predicate = predicate.Or(e => e.DataNascimento.ToString().Contains(searchValue)); } return(predicate); }
/// <summary> /// combine linqkit predicate /// </summary> /// <returns></returns> public ExpressionStarter <T> GetPredicate() { ExpressionStarter <T> linqkitFilter = PredicateBuilder.New <T>(true); _filters.Get()? .ToList() .ForEach(x => { switch (x.Key) { case AppendPredicateWith.And: linqkitFilter = linqkitFilter.And(x.Value); break; case AppendPredicateWith.Or: linqkitFilter = linqkitFilter.Or(x.Value); break; } }); return(linqkitFilter); }
public static ExpressionStarter <ResCurrentType> Build(ResourceSearch <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> NewPredicate, SearchParameterBase SearchItem) { if (SearchItem is SearchParameterQuantity) { var SearchTypeNumber = SearchItem as SearchParameterQuantity; foreach (var SearchValue in SearchTypeNumber.ValueList) { if (SearchTypeNumber.Modifier.HasValue == false) { if (SearchValue.Prefix.HasValue == false) { NewPredicate = CollectionEqualToPredicate(Search, NewPredicate, SearchTypeNumber, SearchValue); } else { switch (SearchValue.Prefix) { case SearchParameter.SearchComparator.Eq: NewPredicate = CollectionEqualToPredicate(Search, NewPredicate, SearchTypeNumber, SearchValue); break; case SearchParameter.SearchComparator.Ne: NewPredicate = CollectionNotEqualToPredicate(Search, NewPredicate, SearchTypeNumber, SearchValue); break; case SearchParameter.SearchComparator.Gt: NewPredicate = NewPredicate.Or(Search.QuantityCollectionAnyGreaterThan(SearchTypeNumber.Id, SearchValue.Value, SearchValue.System, SearchValue.Code)); break; case SearchParameter.SearchComparator.Lt: NewPredicate = NewPredicate.Or(Search.QuantityCollectionAnyLessThan(SearchTypeNumber.Id, SearchValue.Value, SearchValue.System, SearchValue.Code)); break; case SearchParameter.SearchComparator.Ge: NewPredicate = NewPredicate.Or(Search.QuantityCollectionAnyGreaterThanOrEqualTo(SearchTypeNumber.Id, SearchValue.Value, SearchValue.System, SearchValue.Code)); break; case SearchParameter.SearchComparator.Le: NewPredicate = NewPredicate.Or(Search.QuantityCollectionAnyLessThanOrEqualTo(SearchTypeNumber.Id, SearchValue.Value, SearchValue.System, SearchValue.Code)); break; case SearchParameter.SearchComparator.Sa: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of Quantity."); case SearchParameter.SearchComparator.Eb: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of Quantity."); case SearchParameter.SearchComparator.Ap: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of Quantity."); default: throw new System.ComponentModel.InvalidEnumArgumentException(SearchValue.Prefix.Value.GetLiteral(), (int)SearchValue.Prefix, typeof(SearchParameter.SearchComparator)); } } } else { switch (SearchTypeNumber.Modifier) { case SearchParameter.SearchModifierCode.Missing: if (SearchValue.Prefix.HasValue == false) { if (SearchValue.IsMissing) { NewPredicate = NewPredicate.Or(Search.SearchParameterIsNull <ResIndexQuantityType>(SearchTypeNumber.Id)); } else { NewPredicate = NewPredicate.Or(Search.SearchParameterIdIsNotNull <ResIndexQuantityType>(SearchTypeNumber.Id)); } } else { switch (SearchValue.Prefix) { case SearchParameter.SearchComparator.Eq: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of Quantity with a Modifier of: {SearchTypeNumber.Modifier.ToString()}."); case SearchParameter.SearchComparator.Ne: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of Quantity with a Modifier of: {SearchTypeNumber.Modifier.ToString()}."); case SearchParameter.SearchComparator.Gt: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of Quantity with a Modifier of: {SearchTypeNumber.Modifier.ToString()}."); case SearchParameter.SearchComparator.Lt: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of Quantity with a Modifier of: {SearchTypeNumber.Modifier.ToString()}."); case SearchParameter.SearchComparator.Ge: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of Quantity with a Modifier of: {SearchTypeNumber.Modifier.ToString()}."); case SearchParameter.SearchComparator.Le: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of Quantity with a Modifier of: {SearchTypeNumber.Modifier.ToString()}."); case SearchParameter.SearchComparator.Sa: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of Quantity with a Modifier of: {SearchTypeNumber.Modifier.ToString()}."); case SearchParameter.SearchComparator.Eb: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of Quantity with a Modifier of: {SearchTypeNumber.Modifier.ToString()}."); case SearchParameter.SearchComparator.Ap: throw new FormatException($"The search prefix: {SearchValue.Prefix.ToString()} is not supported for search parameter types of Quantity with a Modifier of: {SearchTypeNumber.Modifier.ToString()}."); default: throw new System.ComponentModel.InvalidEnumArgumentException(SearchValue.Prefix.Value.GetLiteral(), (int)SearchValue.Prefix, typeof(SearchParameter.SearchComparator)); } } break; case SearchParameter.SearchModifierCode.Exact: throw new FormatException($"The search modifier: {SearchTypeNumber.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.Contains: throw new FormatException($"The search modifier: {SearchTypeNumber.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.Text: throw new FormatException($"The search modifier: {SearchTypeNumber.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.Type: throw new FormatException($"The search modifier: {SearchTypeNumber.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.Below: throw new FormatException($"The search modifier: {SearchTypeNumber.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.Above: throw new FormatException($"The search modifier: {SearchTypeNumber.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.In: throw new FormatException($"The search modifier: {SearchTypeNumber.Modifier.ToString()} is not supported for search parameter types of date."); case SearchParameter.SearchModifierCode.NotIn: throw new FormatException($"The search modifier: {SearchTypeNumber.Modifier.ToString()} is not supported for search parameter types of date."); default: throw new System.ComponentModel.InvalidEnumArgumentException(SearchTypeNumber.Modifier.Value.GetLiteral(), (int)SearchTypeNumber.Modifier, typeof(SearchParameter.SearchModifierCode)); } } } } return(NewPredicate); }
private static ExpressionStarter <T> HandleText <T>(ExpressionStarter <T> predicate, object value, string domainName, PropertyComparisonTypeEnum propertyComparison, ExpressionCombinationTypeEnum expressionCombination, Type type, bool toLower) { if (value == null) { return(predicate); } if (CheckIfDefaultValue(value, type)) { return(predicate); } Expression <Func <T, bool> > condition = null; switch (propertyComparison) { case PropertyComparisonTypeEnum.Equals: if (type.Name.ToLower().Contains("char")) { condition = GetExpressionEqual <T>(domainName, value); } else { condition = toLower == true?GetExpressionEqualWithToLower <T>(domainName, value) : GetExpressionEqual <T>(domainName, value); } break; case PropertyComparisonTypeEnum.Contains: if (type.Name.ToLower().Contains("char")) { condition = GetExpressionContains <T>(domainName, value); } else { condition = toLower == true?GetExpressionContainsWithToLower <T>(domainName, value) : GetExpressionContains <T>(domainName, value); } break; case PropertyComparisonTypeEnum.NotEqual: condition = GetExpressionNotEqual <T>(domainName, value); break; default: if (type.Name.ToLower().Contains("char")) { condition = GetExpressionEqual <T>(domainName, value); } else { condition = toLower == true?GetExpressionEqualWithToLower <T>(domainName, value) : GetExpressionEqual <T>(domainName, value); } break; } switch (expressionCombination) { case ExpressionCombinationTypeEnum.And: predicate.And(condition); break; case ExpressionCombinationTypeEnum.Or: predicate.Or(condition); break; default: predicate.And(condition); break; } return(predicate); }
/// <summary> /// Extends the specified source Predicate with another Predicate and the specified PredicateOperator. /// </summary> /// <typeparam name="T">The type</typeparam> /// <param name="first">The source Predicate.</param> /// <param name="second">The second Predicate.</param> /// <param name="operator">The Operator (can be "And" or "Or").</param> /// <returns>Expression{Func{T, bool}}</returns> public static Expression <Func <T, bool> > Extend <T>([NotNull] this ExpressionStarter <T> first, [NotNull] Expression <Func <T, bool> > second, PredicateOperator @operator = PredicateOperator.Or) { return(@operator == PredicateOperator.Or ? first.Or(second) : first.And(second)); }