Пример #1
0
        public async Task <IEnumerable <Trip> > SearchAsync(TripSearchRequest request)
        {
            // Search for offered trips
            var offeredTrips = tripOfferRepo.Query()
                               .Where(t => request.Start.Equals(t.StartLocation))
                               .Where(t => request.End.Equals(t.EndLocation))
                               .Where(t => t.StartTime >= request.StartTime);

            // Search for trips provided by public transport
            var publicTrips = new List <Trip>();

            foreach (var provider in publicTransportProviders)
            {
                try {
                    var providerResult = await provider.SearchAsync(request);

                    publicTrips.AddRange(providerResult);
                } catch (Exception ex) {
                    logger.LogWarning(ex, "Provider '{0}' failed while searching for trips!", provider.GetType().Name);
                }
            }

            // Concat and order by duration
            return(offeredTrips
                   .Concat(publicTrips)
                   .OrderBy(t => t.StartTime)
                   .ThenBy(t => t.EstimatedDuration));
        }