Beispiel #1
0
        public static AccommodationSearchResponse Process(Settings settings, SuperAvailabilityResponse superAvailabilityResponse, AggregatorSetting aggregatorSetting, string rooms)
        {
            if (superAvailabilityResponse == null)
            {
                return(new AccommodationSearchResponse
                {
                    Message = new Message
                    {
                        Success = false,
                        Errors = new List <string> {
                            "There was no Search results returned due to an error"
                        }
                    },
                    Results = null,
                    SearchResultSetGuid = new Guid()
                });
            }
            var returnHotels = new List <AccommodationSearchResponseHotel>();

            var getTheIataFromCity = (settings.LookupSettings.CityAsIata.ContainsKey((int)superAvailabilityResponse.AvailabilityRequest.CityCode) ?  settings.LookupSettings.CityAsIata[(int)superAvailabilityResponse.AvailabilityRequest.CityCode] : null) ?? "-1";
            var destinationMarkup  = (settings.LookupSettings.DestinationMarkup.ContainsKey(getTheIataFromCity) ? settings.LookupSettings.DestinationMarkup[getTheIataFromCity] : null) ?? settings.LookupSettings.DestinationMarkup["-1"];

            var transfers = new Dictionary <int, decimal>();

            // loop through each hotel
            if (superAvailabilityResponse.SuperHotelAvailabilityDetail != null)
            {
                if (aggregatorSetting.UserName.ToLower() == "tripadvisor")
                {
                    // loop through the hotels and see if there are any compulsory
                    foreach (var hotel in superAvailabilityResponse.SuperHotelAvailabilityDetail)
                    {
                        foreach (var room in hotel.Hotels)
                        {
                            if (room.TransferCompulsory && room.HotelLocationID.HasValue && !transfers.ContainsKey(room.HotelLocationID.Value))
                            {
                                transfers.Add(room.HotelLocationID.Value, -1);
                            }
                        }
                    }

                    TransferService.GetTransfers(transfers, superAvailabilityResponse, aggregatorSetting);
                }

                foreach (var hotel in superAvailabilityResponse.SuperHotelAvailabilityDetail)
                {
                    int star;
                    if (!string.IsNullOrEmpty(hotel.SuperHotelCategory) && int.TryParse(hotel.SuperHotelCategory.Substring(0, 1), out star))
                    {
                        // do nothing
                    }
                    else
                    {
                        star = 0;
                    }

                    // convert the hotel ready
                    var returnHotel  = ConvertService.Convert(hotel, star);
                    var hotelId      = int.Parse(hotel.SuperHotelID);
                    var hotelMarkups = settings.LookupSettings.HotelMarkup.ContainsKey(hotelId) ? settings.LookupSettings.HotelMarkup[hotelId] : null;



                    // loop through each room
                    foreach (var room in hotel.Hotels)
                    {
                        // see if we need to find out transfers

                        // hotel markup rules
                        if (hotelMarkups != null)
                        {
                            if (hotelMarkups.IsPercentageMarkup)
                            {
                                room.Price += (room.Price / 100m) * hotelMarkups.Markup;
                            }
                            else
                            {
                                room.Price += hotelMarkups.Markup;
                            }
                        }
                        else
                        {
                            // now apply a destination markup
                            foreach (var markupDestination in destinationMarkup)
                            {
                                if (room.Price > markupDestination.MinPriceTakesEffect)
                                {
                                    if (markupDestination.IsPercentageMarkup)
                                    {
                                        room.Price += (room.Price / 100m) * markupDestination.Markup;
                                    }
                                    else
                                    {
                                        room.Price += markupDestination.Markup;
                                    }
                                    break;
                                }
                            }
                        }

                        // apply transfers if needed
                        //if (room.HotelLocationID.HasValue && room.TransferCompulsory && transfers.ContainsKey(room.HotelLocationID.Value))
                        //{
                        //    if (transfers[room.HotelLocationID.Value] == -1)
                        //        continue;
                        //    room.MarkupTotals.FixedTotal += transfers[room.HotelLocationID.Value];/}

                        // round the price off
                        room.Price = Math.Round(room.Price, 2);

                        // convert to the object to return
                        returnHotel.Rooms.Add(ConvertService.Convert(room, aggregatorSetting, hotel.SuperHotelID, rooms));
                    }

                    if (returnHotel.Rooms.Any())
                    {
                        returnHotels.Add(returnHotel);
                    }
                }
            }
            var returnResult = new AccommodationSearchResponse
            {
                Message = new Message
                {
                    Success = true
                },
                Results             = returnHotels,
                SearchResultSetGuid = superAvailabilityResponse.ResultID == null ? new Guid() : new Guid(superAvailabilityResponse.ResultID)
            };

            return(returnResult);
        }
Beispiel #2
0
        /// <summary>
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        /// <param name="accommodation"></param>
        private static void ParseResultSet(TripAdvisorRequest request, TripAdvisorResponse response, AccommodationSearchResponse accommodation)
        {
            try
            {
                // pass any errors over
                response.errors = accommodation.Message.Errors;

                response.api_version = 4;

                response.hotel_ids = new List <int>();
                foreach (var hotels in request.Hotels)
                {
                    response.hotel_ids.Add(hotels.ta_id);
                }

                response.start_date   = request.StartDate.ToString("yyyy-MM-dd");
                response.end_date     = request.EndDate.ToString("yyyy-MM-dd");
                response.num_adults   = request.Adults;
                response.num_rooms    = request.Rooms;
                response.currency     = request.currency;
                response.user_country = request.user_country;
                response.device_type  = request.device_type;
                response.query_key    = request.QueryKey;
                response.lang         = "en_GB";
                response.hotels       = new List <TripAdvisorResponseHotel>();
                response.num_hotels   = 0;

                if (accommodation.Results == null)
                {
                    return;
                }


                response.num_hotels = accommodation.Results.Count;

                // hotels here
                foreach (var hotel in accommodation.Results)
                {
                    var returnHotel = new TripAdvisorResponseHotel();

                    foreach (var tripAdvisorRequestHotelse in request.Hotels)
                    {
                        if (tripAdvisorRequestHotelse.partner_id == hotel.SuperId)
                        {
                            returnHotel.hotel_id = tripAdvisorRequestHotelse.ta_id;
                            break;
                        }
                    }

                    returnHotel.room_types = new Dictionary <string, TripAdvisorResponseRoomTypes>();

                    hotel.Rooms = (from rooms in hotel.Rooms
                                   orderby rooms.Price
                                   select rooms).ToList();
                    foreach (var room in hotel.Rooms)
                    {
                        var returnRoom = new TripAdvisorResponseRoomTypes
                        {
                            url               = room.DeepLink,
                            price             = room.Price,
                            taxes             = 0,
                            taxes_at_checkout = 0,
                            fees              = 0,
                            fees_at_checkout  = 0,
                            final_price       = room.Price,
                            currency          = "GBP",
                            num_rooms         = request.Rooms
                        };

                        if (!returnHotel.room_types.ContainsKey(room.RoomTitle))
                        {
                            returnHotel.room_types.Add(room.RoomTitle, returnRoom);
                        }
                    }
                    response.hotels.Add(returnHotel);
                }
            }
            catch (Exception exception)
            {
                ErrorHelper.SendErrorEmail(exception, "Error parsing results into trip advisor object " + Environment.NewLine + request, InitializeService.Settings);
            }
        }