public Expression <Func <User, bool> > GetUserExpression(SearchUserVm templateUser) { ExpressionStarter <User> userCondition = PredicateBuilder.New <User>(); if (!string.IsNullOrWhiteSpace(templateUser.NameFirst)) { userCondition = userCondition.And(user => user.NameFirst.ToLower() == templateUser.NameFirst.ToLower()); } if (!string.IsNullOrWhiteSpace(templateUser.NameSecond)) { userCondition = userCondition.And(user => user.NameSecond.ToLower() == templateUser.NameSecond.ToLower()); } if (!string.IsNullOrWhiteSpace(templateUser.City)) { userCondition = userCondition.And(user => user.City.ToLower() == templateUser.City.ToLower()); } if (!string.IsNullOrWhiteSpace(templateUser.Country)) { userCondition = userCondition.And(user => user.Country.ToLower() == templateUser.Country.ToLower()); } if (templateUser.Birthday != null) { userCondition = userCondition.And(user => user.Birthday == templateUser.Birthday); } if (templateUser.Tag != null) { userCondition = userCondition.And(user => user.Tag == templateUser.Tag); } return((Expression <Func <User, bool> >)userCondition.Expand()); }
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()); }
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()); }
public Expression <Func <Chat, bool> > GetChatExpression(SearchChatVm templateChat) { ExpressionStarter <Chat> chatCondition = PredicateBuilder.New <Chat>(); if (!string.IsNullOrWhiteSpace(templateChat.Name)) { chatCondition = chatCondition.And(chat => chat.Name.ToLower() == templateChat.Name.ToLower()); } if (templateChat.Tag != null) { chatCondition = chatCondition.And(chat => chat.Tag == templateChat.Tag); } return((Expression <Func <Chat, bool> >)chatCondition.Expand()); }
public void ExpressionStarter_CanBeAssignedFromExpression() { ExpressionStarter <string> predicate = (Expression <Func <string, bool> >)(s => s == "a"); Assert.Equal("s => (s == \"a\")", predicate.Expand().ToString()); }
public void ExpressionStarter_Null() { ExpressionStarter <string> predicate = null; Assert.Null(predicate.Expand()); }