/// <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> /// 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; }