public ActionResult HotelSearch(int noOfPeople, int noOfRooms, string hotelLocation, string currentLocation) { HotelClient hotel = new HotelClient(noOfPeople, noOfRooms, hotelLocation, currentLocation); BaseHotelSearchRsp hotelResponse = hotel.HotelAvailabilty(); HotelSearchResult[] response = hotelResponse.HotelSearchResult; List <HotelProperty> result = new List <HotelProperty>(); foreach (HotelSearchResult rsp in response) { foreach (HotelProperty prop in rsp.HotelProperty) { result.Add(prop); } } ViewBag.result = result; return(View()); }
static void Main(string[] args) { HotelTutorial hotel = new HotelTutorial(); BaseHotelSearchRsp hotelResponse = hotel.HotelAvailabilty();// Get Hotel Availability HostToken hostToken = new HostToken(); if (hotelResponse != null && hotelResponse.HotelSearchResult.Count() > 0) { HotelDetailsRsp hotelDetailsResponse = hotel.HotelDetails(hotelResponse);// Get HotelDetails for the cheapest available hotel if (hotelResponse.HostToken != null) { hostToken = hotelResponse.HostToken; } if (hotelDetailsResponse != null) { hotel.HotelBook(hotelDetailsResponse, hostToken); //send the selected hotelDetails and rates to book the hotel } } }
/// <summary> /// Create hotel Search request and get hotel availability /// </summary> /// <returns></returns> /// public BaseHotelSearchRsp HotelAvailabilty() { //Create Hotel Search Availabilty Request HotelSearchAvailabilityReq hotelSearchAvailabilityRequest = new HotelSearchAvailabilityReq(); // Create an instance of HotelSearchReq and set the //required parameters hotelSearchAvailabilityRequest.TargetBranch = CommonUtility.GetConfigValue(ProjectConstants.G_TARGET_BRANCH); hotelSearchAvailabilityRequest.TraceId = "Trace"; hotelSearchAvailabilityRequest.AuthorizedBy = "user"; //Add billing point of sale information HotelService.BillingPointOfSaleInfo billSaleInfo = new HotelService.BillingPointOfSaleInfo(); billSaleInfo.OriginApplication = CommonUtility.GetConfigValue(ProjectConstants.APP); hotelSearchAvailabilityRequest.BillingPointOfSaleInfo = billSaleInfo; HotelSearchLocation hotelSearchLocation = new HotelSearchLocation(); hotelSearchLocation.HotelLocation = new HotelLocation() { Location = hotelLoc, LocationType = typeHotelLocation.City }; hotelSearchAvailabilityRequest.HotelSearchLocation = hotelSearchLocation; HotelService.HotelStay hotelStay = GetHotelStay(); hotelSearchAvailabilityRequest.HotelStay = hotelStay; HotelSearchModifiers hotelSearchModifiers = new HotelSearchModifiers() { NumberOfAdults = numberOfAdults, NumberOfRooms = numberOfRooms, PermittedProviders = new HotelService.PermittedProviders() { Provider = new HotelService.Provider() { Code = providerCode } }, AvailableHotelsOnly = true }; hotelSearchAvailabilityRequest.HotelSearchModifiers = hotelSearchModifiers; HotelSearchServicePortTypeClient hotelSearchclient = new HotelSearchServicePortTypeClient("HotelSearchServicePort", WsdlService.HOTEL_ENDPOINT); // This is the solution if you get 'object readony exception' => "https://stackoverflow.com/questions/199014/getting-object-is-read-only-error-when-setting-clientcredentials-in-wcf" hotelSearchclient.ClientCredentials.UserName.UserName = Helper.RetrunUsername(); hotelSearchclient.ClientCredentials.UserName.Password = Helper.ReturnPassword(); try { var httpHeaders = Helper.ReturnHttpHeader(); //hotelSearchclient.Endpoint.EndpointBehaviors.RemoveAt(1); hotelSearchclient.Endpoint.EndpointBehaviors.Add(new HttpHeadersEndpointBehavior(httpHeaders)); hotelSearchAvailabilityResponse = hotelSearchclient.service(hotelSearchAvailabilityRequest); } catch (Exception se) { hotelSearchclient.Abort(); } return(hotelSearchAvailabilityResponse); }
/// <summary> /// Select the cheapest hotel from the available hotels and get the details of the selected hotel /// </summary> /// <param name="hotelResponse"></param> /// <returns></returns> /// public HotelDetailsRsp HotelDetails(BaseHotelSearchRsp hotelResponse) { HotelSearchResult closest = null; HotelSearchResult cheapest = null; int lowestDistance = Int32.MaxValue; double lowestPrice = Int32.MaxValue; IEnumerator <HotelSearchResult> searchResults = hotelResponse.HotelSearchResult.ToList().GetEnumerator(); while (searchResults.MoveNext()) { HotelSearchResult result = searchResults.Current; IEnumerator <HotelService.HotelProperty> hotelProperties = result.HotelProperty.ToList().GetEnumerator(); if (result.RateInfo != null && result.RateInfo.Count() > 0) { while (hotelProperties.MoveNext()) { HotelService.HotelProperty property = hotelProperties.Current; if (property.Availability.CompareTo(HotelService.typeHotelAvailability.Available) == 0) { if (property.ReserveRequirement.CompareTo(HotelService.typeReserveRequirement.Other) == 0) { continue; } if (property.Distance != null) //check lowest distance for closet hotel from the reference point { int distance = Convert.ToInt32(property.Distance.Value); if (distance < lowestDistance) { ClosestHotelCode = property.HotelCode; closest = result; lowestDistance = distance; } } IEnumerator <RateInfo> hotelRates = result.RateInfo.ToList().GetEnumerator(); while (hotelRates.MoveNext()) { RateInfo rate = hotelRates.Current; double minRate = 0.0; if (rate.MinimumAmount != null) { minRate = Helper.parseNumberWithCurrency(rate.MinimumAmount); } else if (rate.ApproximateMinimumStayAmount != null) { minRate = Helper.parseNumberWithCurrency(rate.ApproximateMinimumStayAmount); } else if (rate.ApproximateMinimumAmount != null) { minRate = Helper.parseNumberWithCurrency(rate.ApproximateMinimumAmount); } if (minRate == 0.0) { if (rate.MaximumAmount != null) { minRate = Helper.parseNumberWithCurrency(rate.MaximumAmount) / 2; } else if (rate.ApproximateMinimumAmount != null) { minRate = Helper.parseNumberWithCurrency(rate.ApproximateMinimumAmount) / 2; } else if (rate.ApproximateMaximumAmount != null) { minRate = Helper.parseNumberWithCurrency(rate.ApproximateMaximumAmount) / 2; } } if (minRate < lowestPrice)/// Check the lowest price { CheapestHotelCode = property.HotelCode; cheapest = result; lowestPrice = minRate; if (rate.RateSupplier != null) { RateSupplier = rate.RateSupplier; } } } } } } } if (hotelResponse.HostToken != null) { hostToken = hotelResponse.HostToken; } if (closest == null) { HotelSearchResult[] hotelSearchResult = new HotelSearchResult[1]; hotelSearchResult[0] = cheapest; } HotelSearchResult[] hotelSearchResultBoth = new HotelSearchResult[2]; hotelSearchResultBoth[0] = cheapest; hotelSearchResultBoth[1] = closest; HotelDetailsReq detailsRequest = new HotelDetailsReq(); detailsRequest.TargetBranch = CommonUtility.GetConfigValue(ProjectConstants.G_TARGET_BRANCH); detailsRequest.TraceId = "Trace"; detailsRequest.AuthorizedBy = "User"; detailsRequest.ReturnMediaLinks = true; HotelService.BillingPointOfSaleInfo billSaleInfo = new HotelService.BillingPointOfSaleInfo(); billSaleInfo.OriginApplication = CommonUtility.GetConfigValue(ProjectConstants.APP); detailsRequest.BillingPointOfSaleInfo = billSaleInfo; detailsRequest.HotelProperty = cheapest.HotelProperty[0];// Cheapsest hotel selected HotelService.HotelDetailsModifiers hotelDetailsModifiers = new HotelService.HotelDetailsModifiers(); hotelDetailsModifiers.HotelStay = GetHotelStay(); hotelDetailsModifiers.NumberOfAdults = numberOfAdults; hotelDetailsModifiers.NumberOfRooms = numberOfRooms; hotelDetailsModifiers.RateRuleDetail = HotelService.typeRateRuleDetail.Complete; hotelDetailsModifiers.PermittedProviders = new HotelService.PermittedProviders() { Provider = new HotelService.Provider() { Code = providerCode } }; detailsRequest.HotelDetailsModifiers = hotelDetailsModifiers; HotelDetailsServicePortTypeClient detailsClient = new HotelDetailsServicePortTypeClient("HotelDetailsServicePort", WsdlService.HOTEL_ENDPOINT); detailsClient.ClientCredentials.UserName.UserName = Helper.RetrunUsername(); detailsClient.ClientCredentials.UserName.Password = Helper.ReturnPassword(); try { var httpHeaders = Helper.ReturnHttpHeader(); detailsClient.Endpoint.EndpointBehaviors.Add(new HttpHeadersEndpointBehavior(httpHeaders)); detailsResponse = detailsClient.service(detailsRequest); } catch (Exception se) { detailsClient.Abort(); } HotelRulesRsp hotelRulesResponse = HotelRules(cheapest.HotelProperty[0]); return(detailsResponse); }
/// <summary> /// Create hotel Search request and get hotel availability /// </summary> /// <returns></returns> public BaseHotelSearchRsp HotelAvailabilty() { //Create Hotel Search Availabilty Request HotelSearchAvailabilityReq hotelSearchAvailabilityRequest = new HotelSearchAvailabilityReq(); // Create an instance of HotelSearchReq and set the //required parameters hotelSearchAvailabilityRequest.TargetBranch = CommonUtility.GetConfigValue(ProjectConstants.G_TARGET_BRANCH); hotelSearchAvailabilityRequest.TraceId = "Trace"; hotelSearchAvailabilityRequest.AuthorizedBy = "user"; //Add billing point of sale information HotelService.BillingPointOfSaleInfo billSaleInfo = new HotelService.BillingPointOfSaleInfo(); billSaleInfo.OriginApplication = CommonUtility.GetConfigValue(ProjectConstants.APP); hotelSearchAvailabilityRequest.BillingPointOfSaleInfo = billSaleInfo; HotelSearchLocation hotelSearchLocation = new HotelSearchLocation(); hotelSearchLocation.HotelLocation = new HotelLocation() { Location = hotelLoc, LocationType = typeHotelLocation.City }; hotelSearchLocation.ReferencePoint = new typeHotelReferencePoint() { Value = hotelRefPoint }; hotelSearchAvailabilityRequest.HotelSearchLocation = hotelSearchLocation; HotelService.HotelStay hotelStay = GetHotelStay(); hotelSearchAvailabilityRequest.HotelStay = hotelStay; HotelSearchModifiers hotelSearchModifiers = new HotelSearchModifiers() { NumberOfAdults = numberOfAdults, NumberOfRooms = numberOfRooms, PermittedProviders = new HotelService.PermittedProviders(){ Provider = new HotelService.Provider(){ Code = providerCode } }, AvailableHotelsOnly = true, }; hotelSearchAvailabilityRequest.HotelSearchModifiers = hotelSearchModifiers; HotelSearchServicePortTypeClient hotelSearchclient = new HotelSearchServicePortTypeClient("HotelSearchServicePort", WsdlService.HOTEL_ENDPOINT); hotelSearchclient.ClientCredentials.UserName.UserName = Helper.RetrunUsername(); hotelSearchclient.ClientCredentials.UserName.Password = Helper.ReturnPassword(); try { var httpHeaders = Helper.ReturnHttpHeader(); hotelSearchclient.Endpoint.EndpointBehaviors.Add(new HttpHeadersEndpointBehavior(httpHeaders)); hotelSearchAvailabilityResponse = hotelSearchclient.service(hotelSearchAvailabilityRequest); Console.WriteLine(hotelSearchAvailabilityResponse.HotelSearchResult.Count()); } catch (Exception se) { Console.WriteLine("Error : " + se.Message); hotelSearchclient.Abort(); } return hotelSearchAvailabilityResponse; }
/// <summary> /// Select the cheapest hotel from the available hotels and get the details of the selected hotel /// </summary> /// <param name="hotelResponse"></param> /// <returns></returns> public HotelDetailsRsp HotelDetails(BaseHotelSearchRsp hotelResponse) { HotelSearchResult closest = null; HotelSearchResult cheapest = null; int lowestDistance = Int32.MaxValue; double lowestPrice = Int32.MaxValue; IEnumerator<HotelSearchResult> searchResults = hotelResponse.HotelSearchResult.ToList().GetEnumerator(); while (searchResults.MoveNext()) { HotelSearchResult result = searchResults.Current; IEnumerator<HotelService.HotelProperty> hotelProperties = result.HotelProperty.ToList().GetEnumerator(); if(result.RateInfo != null && result.RateInfo.Count() > 0) { while (hotelProperties.MoveNext()) { HotelService.HotelProperty property = hotelProperties.Current; if (property.ReserveRequirement.CompareTo(HotelService.typeReserveRequirement.Other) == 0) { continue; } if (property.Distance != null)//check lowest distance for closet hotel from the reference point { int distance = Convert.ToInt32(property.Distance.Value); if (distance < lowestDistance) { ClosestHotelCode = property.HotelCode; closest = result; lowestDistance = distance; } } IEnumerator<RateInfo> hotelRates = result.RateInfo.ToList().GetEnumerator(); while (hotelRates.MoveNext()) { RateInfo rate = hotelRates.Current; double minRate = 0.0; if (rate.MinimumAmount != null) { minRate = Helper.parseNumberWithCurrency(rate.MinimumAmount); } else if (rate.ApproximateMinimumStayAmount != null) { minRate = Helper.parseNumberWithCurrency(rate.ApproximateMinimumStayAmount); } else if (rate.ApproximateMinimumAmount != null) { minRate = Helper.parseNumberWithCurrency(rate.ApproximateMinimumAmount); } if (minRate == 0.0) { if (rate.MaximumAmount != null) { minRate = Helper.parseNumberWithCurrency(rate.MaximumAmount)/2; } else if (rate.ApproximateAverageMinimumAmount != null) { minRate = Helper.parseNumberWithCurrency(rate.ApproximateAverageMinimumAmount)/2; } else if (rate.ApproximateMaximumAmount != null) { minRate = Helper.parseNumberWithCurrency(rate.ApproximateMaximumAmount)/2; } } if (minRate < lowestPrice)/// Check the lowest price { CheapestHotelCode = property.HotelCode; cheapest = result; lowestPrice = minRate; if (rate.RateSupplier != null) { RateSupplier = rate.RateSupplier; } } } } } } if (hotelResponse.HostToken != null) { hostToken = hotelResponse.HostToken; } if (closest == null) { HotelSearchResult[] hotelSearchResult = new HotelSearchResult[1]; hotelSearchResult[0] = cheapest; } HotelSearchResult[] hotelSearchResultBoth = new HotelSearchResult[2]; hotelSearchResultBoth[0] = cheapest; hotelSearchResultBoth[1] = closest; HotelDetailsReq detailsRequest = new HotelDetailsReq(); detailsRequest.TargetBranch = CommonUtility.GetConfigValue(ProjectConstants.G_TARGET_BRANCH); detailsRequest.TraceId = "Trace"; detailsRequest.AuthorizedBy = "User"; detailsRequest.ReturnMediaLinks = true; HotelService.BillingPointOfSaleInfo billSaleInfo = new HotelService.BillingPointOfSaleInfo(); billSaleInfo.OriginApplication = CommonUtility.GetConfigValue(ProjectConstants.APP); detailsRequest.BillingPointOfSaleInfo = billSaleInfo; detailsRequest.HotelProperty = cheapest.HotelProperty[0];// Cheapsest hotel selected HotelService.HotelDetailsModifiers hotelDetailsModifiers = new HotelService.HotelDetailsModifiers(); hotelDetailsModifiers.HotelStay = GetHotelStay(); hotelDetailsModifiers.NumberOfAdults = numberOfAdults; hotelDetailsModifiers.NumberOfRooms = numberOfRooms; hotelDetailsModifiers.RateRuleDetail = HotelService.typeRateRuleDetail.Complete; hotelDetailsModifiers.PermittedProviders = new HotelService.PermittedProviders() { Provider = new HotelService.Provider() { Code = providerCode } }; detailsRequest.HotelDetailsModifiers = hotelDetailsModifiers; HotelDetailsServicePortTypeClient detailsClient = new HotelDetailsServicePortTypeClient("HotelDetailsServicePort", WsdlService.HOTEL_ENDPOINT); detailsClient.ClientCredentials.UserName.UserName = Helper.RetrunUsername(); detailsClient.ClientCredentials.UserName.Password = Helper.ReturnPassword(); try { var httpHeaders = Helper.ReturnHttpHeader(); detailsClient.Endpoint.EndpointBehaviors.Add(new HttpHeadersEndpointBehavior(httpHeaders)); detailsResponse = detailsClient.service(detailsRequest); } catch (Exception se) { Console.WriteLine("Error : " + se.Message); detailsClient.Abort(); } return detailsResponse; }
/// <summary> /// Create hotel Search request and get hotel availability /// </summary> /// <returns></returns> public BaseHotelSearchRsp HotelAvailabilty() { //Create Hotel Search Availabilty Request HotelSearchAvailabilityReq hotelSearchAvailabilityRequest = new HotelSearchAvailabilityReq(); // Create an instance of HotelSearchReq and set the //required parameters hotelSearchAvailabilityRequest.TargetBranch = CommonUtility.GetConfigValue(ProjectConstants.G_TARGET_BRANCH); hotelSearchAvailabilityRequest.TraceId = "Trace"; hotelSearchAvailabilityRequest.AuthorizedBy = "user"; //Add billing point of sale information HotelService.BillingPointOfSaleInfo billSaleInfo = new HotelService.BillingPointOfSaleInfo(); billSaleInfo.OriginApplication = CommonUtility.GetConfigValue(ProjectConstants.APP); hotelSearchAvailabilityRequest.BillingPointOfSaleInfo = billSaleInfo; HotelSearchLocation hotelSearchLocation = new HotelSearchLocation(); hotelSearchLocation.HotelLocation = new HotelLocation() { Location = hotelLoc, LocationType = typeHotelLocation.City }; /*hotelSearchLocation.ReferencePoint = new typeHotelReferencePoint() * { * Value = hotelRefPoint * };*/ /*List<string> streetAddress = new List<string>(); * streetAddress.Add("300 Galleria Pkway"); * * hotelSearchLocation.HotelAddress = new ConsoleApplication2.HotelService.typeStructuredAddress() * { * Street = streetAddress.ToArray() * }; * * * * hotelSearchLocation.HotelAddress.City = "Atlanta";*/ hotelSearchAvailabilityRequest.HotelSearchLocation = hotelSearchLocation; HotelService.HotelStay hotelStay = GetHotelStay(); hotelSearchAvailabilityRequest.HotelStay = hotelStay; //HotelChain hc = new HotelChain(); //hc.Code = "HI"; HotelSearchModifiers hotelSearchModifiers = new HotelSearchModifiers() { NumberOfAdults = numberOfAdults, NumberOfRooms = numberOfRooms, PermittedProviders = new HotelService.PermittedProviders() { Provider = new HotelService.Provider() { Code = providerCode } }, //PermittedChains = new HotelChain[]{hc}, AvailableHotelsOnly = true }; hotelSearchAvailabilityRequest.HotelSearchModifiers = hotelSearchModifiers; HotelSearchServicePortTypeClient hotelSearchclient = new HotelSearchServicePortTypeClient("HotelSearchServicePort", WsdlService.HOTEL_ENDPOINT); hotelSearchclient.ClientCredentials.UserName.UserName = Helper.RetrunUsername(); hotelSearchclient.ClientCredentials.UserName.Password = Helper.ReturnPassword(); try { var httpHeaders = Helper.ReturnHttpHeader(); hotelSearchclient.Endpoint.EndpointBehaviors.Add(new HttpHeadersEndpointBehavior(httpHeaders)); hotelSearchAvailabilityResponse = hotelSearchclient.service(hotelSearchAvailabilityRequest); Console.WriteLine(hotelSearchAvailabilityResponse.HotelSearchResult.Count()); } catch (Exception se) { Console.WriteLine("Error : " + se.Message); hotelSearchclient.Abort(); } return(hotelSearchAvailabilityResponse); }