Esempio n. 1
0
        public static SuperAvailabilityResponse Search(AccommodationSearchRequest request, Settings settings, AggregatorSetting aggregatorSetting, out int searchTime)
        {
            var availabilityRequest = GetRequest(request, aggregatorSetting, settings);

            var authSoapHd = new AuthSoapHd
            {
                strUserName   = aggregatorSetting.PtsUserName,
                strNetwork    = aggregatorSetting.PtsNetwork,
                strPassword   = aggregatorSetting.PtsPassword,
                strUserRef    = "",
                strCustomerIP = "" //HttpContext.Current == null ? String.Empty : (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).Split(',')[0].Trim()
            };


            //"http://172.16.200.174/Tritonroomswsdev/AccommodationServicev2.svc";
            var service = new  AccommodationService {
                Url = aggregatorSetting.PtsUrl, AuthSoapHdValue = authSoapHd, Timeout = aggregatorSetting.PtsTimeOut
            };
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            SuperAvailabilityResponse response = service.GetSuperAvailability(availabilityRequest);

            stopwatch.Stop();
            searchTime = (int)stopwatch.ElapsedMilliseconds;

            return(response);
        }
Esempio n. 2
0
 public static IQueryable <RichAccommodationDetails> BuildSearchQuery(this IQueryable <RichAccommodationDetails> searchQuery,
                                                                      AccommodationSearchRequest searchRequest)
 => searchQuery
 .FilterBySuppliers(searchRequest.Suppliers)
 .FilterByIsActive(searchRequest.IsActive)
 .FilterByDeactivationReasons(searchRequest.DeactivationReasons)
 .FilterByNameQuery(searchRequest.NameQuery)
 .FilterByCountry(searchRequest.CountryId)
 .FilterByLocality(searchRequest.LocalityId)
 .FilterByLocalityZone(searchRequest.LocalityZoneId)
 .FilterByRatings(searchRequest.Ratings)
 .FilterByHasDirectContract(searchRequest.HasDirectContract)
 .FilterByAddressLine(searchRequest.AddressLineQuery)
 .FilterBySkipTop(searchRequest.Skip, searchRequest.Top);
Esempio n. 3
0
        public async Task <List <SlimAccommodationData> > SearchAccommodations(AccommodationSearchRequest request, string languageCode,
                                                                               CancellationToken cancellationToken)
        {
            var accommodations = await _context.Accommodations
                                 .BuildSearchQuery(request)
                                 .Select(ac => new
            {
                Id       = ac.Id,
                Data     = ac.FinalAccommodation,
                IsActive = ac.IsActive
            })
                                 .ToListAsync(cancellationToken);

            return(accommodations
                   .Select(ac => SlimAccommodationDataConverter.Convert(ac.Id, ac.Data, ac.IsActive, languageCode))
                   .ToList());
        }
Esempio n. 4
0
        /// <summary>
        /// </summary>
        /// <param name="request"></param>
        /// <param name="aggregatorSetting"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        private static AvailabilityRequest GetRequest(AccommodationSearchRequest request, AggregatorSetting aggregatorSetting, Settings settings)
        {
            var availabilityRequest = new AvailabilityRequest
            {
                HotelId           = request.SuperIds == null ? null :  string.Join(",", request.SuperIds),
                H2H               = GetH2H(request.CityCode, aggregatorSetting, settings),
                FeatureCode       = aggregatorSetting.PtsFeatureCode,
                DetailLevel       = 5,
                CityCode          = request.CityCode,
                ConfirmationLevel = 0
            };

            TimeSpan ts = request.CheckOut - request.CheckIn;

            availabilityRequest.Nites        = (sbyte)ts.Days;
            availabilityRequest.SvcDate      = request.CheckIn;
            availabilityRequest.NoOfAdults   = (sbyte)request.NumberOfAdults;
            availabilityRequest.NoOfChildren = (sbyte)(request.ChildAge == null ? 0 : request.ChildAge.Count + request.NumberOfInfants ?? 0);
            if (request.ResortCode.HasValue && request.ResortCode.Value > 0)
            {
                availabilityRequest.Location = (int)request.ResortCode.Value;
            }


            var ages = new List <sbyte>();

            if (request.ChildAge != null)
            {
                foreach (var i in request.ChildAge)
                {
                    ages.Add((sbyte)i);
                }
            }

            for (var i = 0; i < request.NumberOfInfants; i++)
            {
                ages.Add(1);
            }

            availabilityRequest.ChildAge = ages.ToArray();
            availabilityRequest.Units    = (sbyte)request.NumberOfRooms;

            return(availabilityRequest);
        }
        public static List <string> ValidateSearch(AccommodationSearchRequest accommodationSearchRequest)
        {
            var errors = new List <string>();

            // first check in
            if (accommodationSearchRequest.CheckIn < DateTime.Now.AddDays(3))
            {
                errors.Add("Check-in must be more that 3 days from now");
            }

            // check out
            if (accommodationSearchRequest.CheckIn > accommodationSearchRequest.CheckOut)
            {
                errors.Add("Check-in must be before checkout");
            }

            if (accommodationSearchRequest.CountryCode < 0)
            {
                errors.Add("Please provide valid country code");
            }

            if (accommodationSearchRequest.CityCode < 0)
            {
                errors.Add("Please provide valid city code");
            }

            if (accommodationSearchRequest.MinStarRating.HasValue)
            {
                if (accommodationSearchRequest.MinStarRating > 5)
                {
                    errors.Add("Min star rating can not be greater than 5");
                }

                if (accommodationSearchRequest.MinStarRating < 0)
                {
                    errors.Add("Min star rating can not be less than 0");
                }
            }

            if (accommodationSearchRequest.PassengerCount() > 10)
            {
                errors.Add("The maximum number of passengers per search is 10");
            }

            if (accommodationSearchRequest.NumberOfRooms < 1 || accommodationSearchRequest.NumberOfRooms > 4)
            {
                errors.Add("Number of rooms must be between 1 and 4");
            }

            if (accommodationSearchRequest.NumberOfAdults < 1)
            {
                errors.Add("There must be 1 or more adults travelling");
            }

            if (accommodationSearchRequest.ChildAge != null)
            {
                var i = 0;
                foreach (var age in accommodationSearchRequest.ChildAge)
                {
                    i++;
                    if (age < 2)
                    {
                        errors.Add("Child " + i + " must be 2 or older");
                    }
                    if (age > 16)
                    {
                        errors.Add("Child " + i + " must be 16 or younger");
                    }
                }
            }

            if (accommodationSearchRequest.NumberOfRooms > 1 && accommodationSearchRequest.ChildAge != null && accommodationSearchRequest.ChildAge.Count != 0)
            {
                errors.Add("Sorry but we don't currently support more than 1 room with children");
            }

            return(errors);
        }
Esempio n. 6
0
        public async Task <Result <List <SlimAccommodationData>, ProblemDetails> > SearchAccommodations(AccommodationSearchRequest request, CancellationToken cancellationToken)
        {
            using var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"api/1.0/admin/accommodations/search")
                  {
                      Content = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json")
                  };

            return(await Send <List <SlimAccommodationData> >(requestMessage, cancellationToken : cancellationToken));
        }
Esempio n. 7
0
 public async Task <IActionResult> SearchAccommodations([FromBody] AccommodationSearchRequest searchRequest, CancellationToken cancellationToken)
 => OkOrBadRequest(await _mapperManagementClient.SearchAccommodations(searchRequest, cancellationToken));
 public AccommodationSearchResponse AccommodationSearch(AccommodationSearchRequest request)
 {
     return(HotelSearch.Search(request, InitializeService.Settings));
 }
        public async Task <IActionResult> SearchAccommodations(AccommodationSearchRequest searchRequest, CancellationToken cancellationToken)
        {
            var accommodations = await _accommodationService.SearchAccommodations(searchRequest, LanguageCode, cancellationToken);

            return(Ok(accommodations));
        }
Esempio n. 10
0
        public static AccommodationSearchResponse Search(AccommodationSearchRequest accommodationSearchRequest, Settings settings)
        {
            // this so we know when we got the request
            var dateOfSearch = DateTime.Now;

            // this is so we can time how long we take to process
            var startOfSearch = new Stopwatch();

            startOfSearch.Start();


            // Check login credentials
            var auth = AuthenticationHelper.CheckAuth(settings, accommodationSearchRequest.Authentication);

            if (!auth.LoginSuccess)
            {
                // they failed to login
                var message = new Message {
                    Success = false
                };

                // add error message if there
                if (!String.IsNullOrEmpty(auth.Error))
                {
                    message.Errors.Add(auth.Error);
                }

                // add warning if not there
                if (!String.IsNullOrEmpty(auth.Warning))
                {
                    message.Warnings.Add(auth.Warning);
                }

                return(new AccommodationSearchResponse {
                    Message = message
                });
            }

            // now we need to check how many searches they have done
            var areWeOkToSearch = TooManySearchesHelper.CheckIfWeAreOkToSearch(auth, settings);

            if (!areWeOkToSearch)
            {
                TooManySearchesHelper.MinusToSearchCount(auth);
                throw new Exception("Speed Limit: Sorry but we have had too many searches at once please try again in a minute");
            }

            try
            {
                //Debug.WriteLine(TooManySearchesHelper.GetCurrentSearchCount(auth));

                // validate Search
                var errors = ValidationHelper.ValidateSearch(accommodationSearchRequest);
                if (errors.Count != 0)
                {
                    // they failed validation
                    var message = new Message {
                        Success = false
                    };
                    // add error messages in
                    foreach (var error in errors)
                    {
                        message.Errors.Add(error);
                    }
                    TooManySearchesHelper.MinusToSearchCount(auth);
                    return(new AccommodationSearchResponse {
                        Message = message
                    });
                }

                var log = new AccommodationSearchLog();

                // do the search
                var isError         = false;
                var errorMessage    = String.Empty;
                int timeToSearchPts = 0;
                SuperAvailabilityResponse ptsResults = null;
                try
                {
                    ptsResults = PtsService.Search(accommodationSearchRequest, settings, auth, out timeToSearchPts);
                }
                catch (Exception exception)
                {
                    log.ConvertSearch(accommodationSearchRequest, auth);
                    log.StartOfSearch        = dateOfSearch;
                    log.TimeToSearchSupplier = timeToSearchPts;
                    log.TimeToSearchTotal    = (int)startOfSearch.ElapsedMilliseconds;
                    log.NumberOfHotelResults = 0;
                    log.Error = exception.Message;
                    settings.LoggingSettings.AccommodationJobHost.AddLog(log);
                    isError      = true;
                    errorMessage = exception.Message;
                }
                // process and add in mark-ups
                var processdResults = ProcessService.Process(settings, ptsResults, auth, accommodationSearchRequest.PassengerUrl());
                if (isError)
                {
                    processdResults.Message.Success = false;
                    processdResults.Message.Errors.Add(errorMessage);
                }

                startOfSearch.Stop();
                log.ConvertSearch(accommodationSearchRequest, auth);
                log.StartOfSearch        = dateOfSearch;
                log.TimeToSearchSupplier = timeToSearchPts;
                log.TimeToSearchTotal    = (int)startOfSearch.ElapsedMilliseconds;
                log.NumberOfHotelResults = processdResults.Results == null ? 0 : processdResults.Results.Count;
                settings.LoggingSettings.AccommodationJobHost.AddLog(log);

                TooManySearchesHelper.MinusToSearchCount(auth);
                return(processdResults);
            }
            catch (Exception ex)
            {
                ErrorHelper.SendErrorEmail(ex, "Error In Search", settings);
                TooManySearchesHelper.MinusToSearchCount(auth);
                throw;
            }
        }