/// <summary>
 /// Applies filtering based on filtering parameters
 /// <para>Supports multiple properties filtering, by formating <see cref="SearchFlightsQuery.SortProperty"/> like <code>"firstProperty.secondProperty.thirdProperty"</code>"/></para>
 /// </summary>
 /// <param name="request"></param>
 /// <param name="result"></param>
 private static void ApplySorting(SearchFlightsQuery request, PaginatedList <SearchFlightsDTO> result)
 {
     if (!string.IsNullOrEmpty(request.SortOrder) && !string.IsNullOrEmpty(request.SortProperty))
     {
         result.Items = result.Items.AsQueryable().SortByColumnAndDirection(request.SortOrder, request.SortProperty);
     }
 }
        public Task <PaginatedList <SearchFlightsDTO> > Handle(SearchFlightsQuery request, CancellationToken cancellationToken)
        {
            List <SearchFlightsDTO> cachedRequestResult;
            int cacheId = request.GetHashCode();

            cachedRequestResult = _inMemoryCache.Get <List <SearchFlightsDTO> >(cacheId);
            if (cachedRequestResult != null)
            {
                var toReturnPaginatedList = cachedRequestResult.AsQueryable().PaginatedListOfData(request.PageNumber, request.PageSize);
                ApplySorting(request, toReturnPaginatedList);
                return(Task.FromResult(toReturnPaginatedList));
            }
            Task <Success2> searchData    = _client.GetFlightOffersAsync(request);
            var             serviceResult = searchData.Result.Data;
            var             resultQuery   = serviceResult.AsQueryable()
                                            .OrderBy(t => t.Id)
                                            .ProjectTo <SearchFlightsDTO>(_mapper.ConfigurationProvider);
            var            listToCache     = resultQuery.ToList();
            var            result          = resultQuery.PaginatedListOfData(request.PageNumber, request.PageSize);
            DateTimeOffset durationOfCache = CalculateCacheTimeout();

            _inMemoryCache.Set <List <SearchFlightsDTO> >(cacheId, listToCache, durationOfCache);
            ApplySorting(request, result);
            return(Task.FromResult(result));
        }
 public bool Equals(SearchFlightsQuery other)
 {
     return(other != null &&
            OriginIATACode == other.OriginIATACode &&
            DestinationIATACode == other.DestinationIATACode &&
            DepartureTime.Equals(other.DepartureTime) &&
            NumberOfAdults == other.NumberOfAdults &&
            EqualityComparer <DateTimeOffset?> .Default.Equals(ReturnDate, other.ReturnDate) &&
            NumberOfChildren == other.NumberOfChildren &&
            NumberOfInfants == other.NumberOfInfants &&
            TravelClass == other.TravelClass &&
            IncludedAirlineCodes == other.IncludedAirlineCodes &&
            ExcludedAirlineCodes == other.ExcludedAirlineCodes &&
            NoStops == other.NoStops &&
            CurrencyCode == other.CurrencyCode &&
            MaxPrice == other.MaxPrice &&
            Max == other.Max);
 }