Ejemplo n.º 1
0
        public async Task <Result <List <RoomContractSet> > > Get(Guid searchId, Guid resultId, AgentContext agent, string languageCode)
        {
            var searchSettings = await _accommodationBookingSettingsService.Get(agent);

            var(_, isFailure, selectedResults, error) = await GetSelectedWideAvailabilityResults(searchId, resultId, agent);

            if (isFailure)
            {
                return(Result.Failure <List <RoomContractSet> >(error));
            }

            var supplierTasks = selectedResults
                                .Select(GetProviderAvailability)
                                .ToArray();

            await Task.WhenAll(supplierTasks);

            return(supplierTasks
                   .Select(task => task.Result)
                   .Where(taskResult => taskResult.IsSuccess)
                   .Select(taskResult => taskResult.Value)
                   .SelectMany(MapToRoomContractSets)
                   .Where(SettingsFilter)
                   .ToList());


            async Task <Result <SupplierData <AccommodationAvailability>, ProblemDetails> > GetProviderAvailability((Suppliers, AccommodationAvailabilityResult) wideAvailabilityResult)
            {
                using var scope = _serviceScopeFactory.CreateScope();

                var(source, result) = wideAvailabilityResult;

                return(await RoomSelectionSearchTask
                       .Create(scope.ServiceProvider)
                       .GetProviderAvailability(searchId, resultId, source, result.Accommodation.Id, result.AvailabilityId, agent, languageCode));
            }

            async Task <Result <List <(Suppliers Source, AccommodationAvailabilityResult Result)> > > GetSelectedWideAvailabilityResults(Guid searchId, Guid resultId, AgentContext agent)
            {
                var results = await GetWideAvailabilityResults(searchId, agent);

                var selectedResult = results
                                     .SingleOrDefault(r => r.Result.Id == resultId);

                if (selectedResult.Equals(default))
Ejemplo n.º 2
0
        public async Task <Result <List <RoomContractSet> > > Get(Guid searchId, string htId, AgentContext agent, string languageCode)
        {
            Baggage.AddSearchId(searchId);
            var searchSettings = await _accommodationBookingSettingsService.Get(agent);

            var(_, isFailure, selectedResults, error) = await GetSelectedWideAvailabilityResults(searchId, htId, agent);

            if (isFailure)
            {
                return(Result.Failure <List <RoomContractSet> >(error));
            }

            var checkInDate = selectedResults
                              .Select(s => s.Result.CheckInDate)
                              .FirstOrDefault();

            var supplierTasks = selectedResults
                                .Select(GetSupplierAvailability)
                                .ToArray();

            await Task.WhenAll(supplierTasks);

            return(supplierTasks
                   .Select(task => task.Result)
                   .Where(taskResult => taskResult.IsSuccess)
                   .Select(taskResult => taskResult.Value)
                   .SelectMany(MapToRoomContractSets)
                   .Where(SettingsFilter)
                   .OrderBy(r => r.Rate.FinalPrice.Amount)
                   .ToList());


            async Task <Result <SingleAccommodationAvailability, ProblemDetails> > GetSupplierAvailability((Suppliers, AccommodationAvailabilityResult) wideAvailabilityResult)
            {
                using var scope = _serviceScopeFactory.CreateScope();

                var(source, result) = wideAvailabilityResult;

                return(await RoomSelectionSearchTask
                       .Create(scope.ServiceProvider)
                       .GetSupplierAvailability(searchId: searchId, htId: htId, supplier: source, supplierAccommodationCode: result.SupplierAccommodationCode,
                                                availabilityId: result.AvailabilityId, settings: searchSettings, agent: agent, languageCode: languageCode,
                                                countryHtId: result.CountryHtId, localityHtId: result.LocalityHtId));
            }

            async Task <Result <List <(Suppliers Source, AccommodationAvailabilityResult Result)> > > GetSelectedWideAvailabilityResults(Guid searchId, string htId, AgentContext agent)
            {
                var results = await GetWideAvailabilityResults(searchId, htId, agent);

                if (searchSettings.PassedDeadlineOffersMode == PassedDeadlineOffersMode.Hide)
                {
                    results = results
                              .Where(r => r.Result.CheckInDate > _dateTimeProvider.UtcTomorrow());
                }

                return(results.ToList());
            }

            IEnumerable <RoomContractSet> MapToRoomContractSets(SingleAccommodationAvailability accommodationAvailability)
            {
                return(accommodationAvailability.RoomContractSets
                       .Select(rs => rs.ApplySearchSettings(searchSettings.IsSupplierVisible, searchSettings.IsDirectContractFlagVisible)));
            }

            bool SettingsFilter(RoomContractSet roomSet)
            => RoomContractSetSettingsChecker.IsDisplayAllowed(roomSet, checkInDate, searchSettings, _dateTimeProvider);
        }