private static Func <TransportServiceInformation, bool> YourCityPredicate(
                INeedTransportServicesRequest message)
            {
                if (string.IsNullOrEmpty(message.YourCity))
                {
                    return(x => true);
                }

                return(x => x.TransportFromCity == message.YourCity);
            }
            private static Func <TransportServiceInformation, bool> TransportTypePredicate(
                INeedTransportServicesRequest message)
            {
                if (!message.TransportTypes.Any())
                {
                    return(x => true);
                }

                return(x => message.TransportTypes.Contains(x.TransportType));
            }
            public static IEnumerable <Func <TransportServiceInformation, bool> > GetFor(
                INeedTransportServicesRequest message)
            {
                yield return(TransportTypePredicate(message));

                yield return(YourCountryPredicate(message));

                yield return(YourCityPredicate(message));

                yield return(ActivityPricePredicate(message));
            }
        public void Handle(INeedTransportServicesRequest message, AID sender)
        {
            List <TransportServiceInformation> transportServiceInformations = Services.GetFor(message).ToList();

            SendMessage(
                sender,
                new FoundTransportServicesResponse
            {
                CorrelationId = message.CorrelationId,
                Tranports     = transportServiceInformations
            });
        }
        public static IEnumerable <TransportServiceInformation> GetFor(
            this IList <TransportServiceInformation> services,
            INeedTransportServicesRequest message)
        {
            IEnumerable <TransportServiceInformation> query = services;

            IEnumerable <Func <TransportServiceInformation, bool> > predicates = SearchPredicates.GetFor(message);

            foreach (Func <TransportServiceInformation, bool> predicate in predicates)
            {
                query = query.Where(predicate);
            }

            return(query);
        }
 private static Func <TransportServiceInformation, bool> ActivityPricePredicate(INeedTransportServicesRequest message)
 {
     if (message.TransportPrice.IsNull())
     {
         return(x => true);
     }
     else if (message.TransportPrice.Min == null && message.TransportPrice.Max != null)
     {
         return(x => message.TransportPrice.Max >= x.Price);
     }
     else if (message.TransportPrice.Min != null && message.TransportPrice.Max == null)
     {
         return(x => message.TransportPrice.Min <= x.Price);
     }
     return(x => x.Price <= message.TransportPrice.Max && x.Price >= message.TransportPrice.Min);
 }