示例#1
0
        public static IEnumerable <WideAvailabilityResult> ApplyTo(this AvailabilitySearchFilter options, IQueryable <WideAvailabilityResult> queryable)
        {
            if (options.MinPrice.HasValue)
            {
                queryable = queryable.Where(a => a.MinPrice >= options.MinPrice);
            }

            if (options.MaxPrice.HasValue)
            {
                queryable = queryable.Where(a => a.MaxPrice <= options.MaxPrice);
            }

            if (options.BoardBasisTypes is not null && options.BoardBasisTypes.Any())
            {
                queryable = queryable.Where(a => a.RoomContractSets.Any(rcs => rcs.Rooms.Any(r => options.BoardBasisTypes.Contains(r.BoardBasis))));
            }

            if (options.Ratings is not null && options.Ratings.Any())
            {
                queryable = queryable.Where(a => options.Ratings.Contains(a.Accommodation.Rating));
            }

            queryable = queryable.Where(a => a.RoomContractSets.Any());

            if (options.Order == "price")
            {
                queryable = options.Direction switch
                {
                    "asc" => queryable.OrderBy(x => x.MinPrice),
                    "desc" => queryable.OrderByDescending(x => x.MinPrice)
                };
            }

            return(queryable
                   .Skip(options.Skip)
                   .Take(options.Top));
        }
    }
 public async Task <IActionResult> GetAvailabilitySearchResult([FromRoute] Guid searchId, [FromQuery] AvailabilitySearchFilter options)
 {
     return(Ok(await _wideAvailabilitySearchService.GetResult(searchId, options, await _agentContextService.GetAgent(), LanguageCode)));
 }
        public async Task <List <WideAvailabilityResult> > GetFilteredResults(Guid searchId, AvailabilitySearchFilter filters, AccommodationBookingSettings searchSettings, List <Suppliers> suppliers, string languageCode)
        {
            var rows = await _availabilityStorage.Collection()
                       .Where(r => r.SearchId == searchId && suppliers.Contains(r.Supplier))
                       .Select(r => new { r.Id, r.HtId, r.Created })
                       .ToListAsync();

            var htIds = new List <string>();
            var ids   = new List <ObjectId>();

            foreach (var group in rows.GroupBy(r => r.HtId))
            {
                htIds.Add(group.Key);
                ids.Add(group.OrderBy(g => g.Created).First().Id);
            }

            await _accommodationsStorage.EnsureAccommodationsCached(htIds, languageCode);

            var query = _availabilityStorage.Collection()
                        .Where(r => r.SearchId == searchId && ids.Contains(r.Id));

            query = filters.Suppliers is not null
                ? query.Where(r => filters.Suppliers.Contains(r.Supplier))
                : query.Where(r => suppliers.Contains(r.Supplier));

            if (filters.MinPrice is not null)
            {
                query = query.Where(r => r.MinPrice >= filters.MinPrice);
            }

            if (filters.MaxPrice is not null)
            {
                query = query.Where(r => r.MaxPrice <= filters.MaxPrice);
            }

            if (filters.BoardBasisTypes is not null)
            {
                query = query.Where(r => r.RoomContractSets.Any(rcs => rcs.Rooms.Any(room => filters.BoardBasisTypes.Contains(room.BoardBasis))));
            }

            if (searchSettings.AprMode == AprMode.Hide)
            {
                query = query.Where(r => r.RoomContractSets.Any(rcs => !rcs.IsAdvancePurchaseRate));
            }

            if (searchSettings.PassedDeadlineOffersMode == PassedDeadlineOffersMode.Hide)
            {
                query = query.Where(r => r.RoomContractSets.Any(rcs => rcs.Deadline.Date == null || rcs.Deadline.Date >= _dateTimeProvider.UtcNow()));
            }

            if (filters.Ratings is not null)
            {
                var filteredHtIds = await GetAccommodationRatings(htIds, filters.Ratings);

                query = query.Where(r => filteredHtIds.Contains(r.HtId));
            }

            if (filters.Order == "price")
            {
                query = filters.Direction switch
                {
                    "asc" => query.OrderBy(x => x.MinPrice),
                    "desc" => query.OrderByDescending(x => x.MinPrice)
                };
            }
            else
            {
                query = query
                        .OrderBy(r => r.Created)
                        .ThenBy(r => r.HtId);
            }

            var results = await query
                          .Skip(filters.Skip)
                          .Take(filters.Top)
                          .ToListAsync();

            return(results
                   .Select(a =>
            {
                var accommodation = _accommodationsStorage.GetAccommodation(a.HtId, languageCode);
                var roomContractSets = a.RoomContractSets
                                       .Select(r => r.ApplySearchSettings(searchSettings.IsSupplierVisible, searchSettings.IsDirectContractFlagVisible))
                                       .ToList();

                if (searchSettings.AprMode == AprMode.Hide)
                {
                    roomContractSets = roomContractSets.Where(r => !r.IsAdvancePurchaseRate).ToList();
                }

                if (searchSettings.PassedDeadlineOffersMode == PassedDeadlineOffersMode.Hide)
                {
                    roomContractSets = roomContractSets.Where(r => r.Deadline.Date == null || r.Deadline.Date >= _dateTimeProvider.UtcNow()).ToList();
                }

                return new WideAvailabilityResult(accommodation: accommodation,
                                                  roomContractSets: roomContractSets,
                                                  minPrice: roomContractSets.Min(r => r.Rate.FinalPrice.Amount),
                                                  maxPrice: roomContractSets.Max(r => r.Rate.FinalPrice.Amount),
                                                  checkInDate: a.CheckInDate,
                                                  checkOutDate: a.CheckOutDate,
                                                  supplier: searchSettings.IsSupplierVisible
                            ? a.Supplier
                            : null,
                                                  htId: a.HtId);
            }).ToList());
        }
示例#4
0
        public async Task <List <WideAvailabilityResult> > GetFilteredResults(Guid searchId, AvailabilitySearchFilter filters, AccommodationBookingSettings searchSettings, List <Suppliers> suppliers, string languageCode)
        {
            var results = await GetResults(searchId, suppliers);

            var availabilities = results.SelectMany(r => r.AccommodationAvailabilities)
                                 .GroupBy(a => a.HtId)
                                 .Select(g => g.OrderBy(a => a.Created).First())
                                 .AsQueryable();

            if (searchSettings.AprMode == AprMode.Hide)
            {
                availabilities = availabilities.Where(a => a.RoomContractSets.All(rcs => !rcs.IsAdvancePurchaseRate));
            }

            if (searchSettings.PassedDeadlineOffersMode == PassedDeadlineOffersMode.Hide)
            {
                availabilities = availabilities.Where(a => a.RoomContractSets.All(rcs => rcs.Deadline.Date == null || rcs.Deadline.Date >= DateTime.UtcNow));
            }

            return(availabilities
                   .OrderBy(a => a.Created)
                   .ThenBy(a => a.HtId)
                   .ToWideAvailabilityResults(searchSettings));
        }
示例#5
0
        public async Task <List <WideAvailabilityResult> > GetFilteredResults(Guid searchId, AvailabilitySearchFilter filters, AccommodationBookingSettings searchSettings, List <Suppliers> suppliers, string languageCode)
        {
            var rows = await _availabilityStorage.Collection()
                       .Where(r => r.SearchId == searchId && suppliers.Contains(r.Supplier))
                       .Select(r => new { r.Id, r.HtId, r.Created })
                       .ToListAsync();

            var ids = rows.GroupBy(r => r.HtId)
                      .Select(group => group.OrderBy(g => g.Created).First().Id)
                      .ToList();

            var query = _availabilityStorage.Collection()
                        .Where(r => r.SearchId == searchId && ids.Contains(r.Id));

            if (searchSettings.AprMode == AprMode.Hide)
            {
                query = query.Where(r => r.RoomContractSets.Any(rcs => !rcs.IsAdvancePurchaseRate));
            }

            if (searchSettings.PassedDeadlineOffersMode == PassedDeadlineOffersMode.Hide)
            {
                query = query.Where(r => r.RoomContractSets.Any(rcs => rcs.Deadline.Date == null || rcs.Deadline.Date >= DateTime.UtcNow));
            }

            return((await query
                    .OrderBy(r => r.Created)
                    .ThenBy(r => r.HtId)
                    .ToListAsync())
                   .ToWideAvailabilityResults(searchSettings));
        }
示例#6
0
        public async Task <List <WideAvailabilityResult> > GetFilteredResults(Guid searchId, AvailabilitySearchFilter filters, AccommodationBookingSettings searchSettings, List <Suppliers> suppliers, string languageCode)
        {
            var results = await GetResults(searchId, suppliers);

            var availabilities = results.SelectMany(r => r.AccommodationAvailabilities)
                                 .GroupBy(a => a.HtId)
                                 .Select(g => g.OrderBy(a => a.Created).First())
                                 .AsQueryable();

            if (searchSettings.AprMode == AprMode.Hide)
            {
                availabilities = availabilities.Where(a => a.RoomContractSets.All(rcs => !rcs.IsAdvancePurchaseRate));
            }

            if (searchSettings.PassedDeadlineOffersMode == PassedDeadlineOffersMode.Hide)
            {
                availabilities = availabilities.Where(a => a.RoomContractSets.All(rcs => rcs.Deadline.Date == null || rcs.Deadline.Date >= _dateTimeProvider.UtcNow()));
            }

            var htIds = availabilities.Select(a => a.HtId).ToList();
            await _accommodationsStorage.EnsureAccommodationsCached(htIds, languageCode);

            var queriable = availabilities
                            .OrderBy(a => a.Created)
                            .ThenBy(a => a.HtId)
                            .ToList()
                            .Select(a =>
            {
                var accommodation = _accommodationsStorage.GetAccommodation(a.HtId, languageCode);

                return(new WideAvailabilityResult(accommodation: accommodation,
                                                  roomContractSets: a.RoomContractSets.Select(r => r.ApplySearchSettings(searchSettings.IsSupplierVisible, searchSettings.IsDirectContractFlagVisible)).ToList(),
                                                  minPrice: a.RoomContractSets.Min(r => r.Rate.FinalPrice.Amount),
                                                  maxPrice: a.RoomContractSets.Max(r => r.Rate.FinalPrice.Amount),
                                                  checkInDate: a.CheckInDate,
                                                  checkOutDate: a.CheckOutDate,
                                                  supplier: searchSettings.IsSupplierVisible
                            ? a.Supplier
                            : null,
                                                  htId: a.HtId));
            })
                            .AsQueryable();

            return(filters.ApplyTo(queriable).ToList());
        }
        public async Task <IEnumerable <WideAvailabilityResult> > GetResult(Guid searchId, AvailabilitySearchFilter options, AgentContext agent, string languageCode)
        {
            Baggage.AddSearchId(searchId);
            var searchSettings = await _accommodationBookingSettingsService.Get(agent);

            var suppliers = options.Suppliers is not null && options.Suppliers.Any()
                ? options.Suppliers.Intersect(searchSettings.EnabledConnectors).ToList()
                : searchSettings.EnabledConnectors;

            return(await _availabilityStorage.GetFilteredResults(searchId, options, searchSettings, suppliers, languageCode));
        }