public PriceEstimatesViewModel() { _oauthUberService = new OAuthUberService(); _oauthOlaService = new OAuthOlaService(); _oauthRestOfCabsService = new OAuthRestOfCabsService(); _oauthUberProvider = new OAuthUberProvider(); _oauthOlaProvider = new OAuthOlaProvider(); _oauthRestOfCabsProvider = new OAuthRestOfCabsProvider(); _oauthOlaProviderList = new List<OAuthOlaProviderResult>(); _oauthUberProviderList = new List<OAuthUberProviderResult>(); _oauthRestOfCabsProviderResult = new List<OAuthRestOfCabsProviderResult>(); ResourceContentLoader = new ResourceLoader(); SortOrder = CabsSortTypes.GetSortTypes(); SortOrderItem = SortOrder[0]; SortCommand = new RelayCommand<SortCabType>(SortCabsList); RefreshPageCommand = new RelayCommand(RefreshPage); LaunchCabAppCommand = new RelayCommand<CabType>(LaunchCabApp); }
public async Task<List<OAuthUberProviderResult>> GetFareEstimates(OAuthUberService oauthService) { HttpClient httpClient = new HttpClient(); HttpResponseMessage priceEstimateResponseMessage = new HttpResponseMessage(); HttpResponseMessage timeEstimateResponseMessage = new HttpResponseMessage(); List<OAuthUberProviderResult> providerResult = new List<OAuthUberProviderResult>(); try { string priceEstimateuri = string.Format(oauthService.RequestUri + "/" + oauthService.RequestPriceEstimate + "?" + Constants.ServerTokenString + "=" + oauthService.ServerToken + "&" + oauthService.SourceLatitudeString + "=" + oauthService.SourceLatitude + "&" + oauthService.SourceLongitudeString + "=" + oauthService.SourceLongitude + "&" + oauthService.DestinationLatitudeString + "=" + oauthService.DestinationLatitude + "&" + oauthService.DestinationLongitudeString + "=" + oauthService.DestinationLongitude); priceEstimateResponseMessage = await httpClient.GetAsync(priceEstimateuri); string timeEstimateUri = string.Format(oauthService.RequestUri + "/" + oauthService.RequestTimeEstimate + "?" + Constants.ServerTokenString + "=" + oauthService.ServerToken + "&" + oauthService.SourceLatitudeString + "=" + oauthService.SourceLatitude + "&" + oauthService.SourceLongitudeString + "=" + oauthService.SourceLongitude); timeEstimateResponseMessage = await httpClient.GetAsync(timeEstimateUri); if (priceEstimateResponseMessage.StatusCode == HttpStatusCode.OK && timeEstimateResponseMessage.StatusCode == HttpStatusCode.OK) { string priceEstimatetoken = await priceEstimateResponseMessage.Content.ReadAsStringAsync(); string timeEstimateToken = await timeEstimateResponseMessage.Content.ReadAsStringAsync(); JObject jsonTimeEstimateString = JObject.Parse(timeEstimateToken); var timeList = jsonTimeEstimateString["times"]; List<UberData> timeEstimateProducts = JsonConvert.DeserializeObject<List<UberData>>(timeList.ToString()); JObject jsonPriceEstimateString = JObject.Parse(priceEstimatetoken); var priceList = jsonPriceEstimateString["prices"]; List<UberData> priceEstimateProducts = JsonConvert.DeserializeObject<List<UberData>>(priceList.ToString()); foreach (var product in timeEstimateProducts) { string productId = product.product_id; string displayName = product.display_name; string timeEstimate = product.estimate; foreach(var prod in priceEstimateProducts) { if (prod.product_id == product.product_id) { string currencyCode = prod.currency_code; string priceEstimate = prod.estimate; string lowEstimate = prod.low_estimate; string highEstimate = prod.high_estimate; string surge = prod.surge_multiplier; string distance = prod.distance; providerResult.Add(new OAuthUberProviderResult(productId, currencyCode, displayName, priceEstimate, lowEstimate, highEstimate, surge, timeEstimate, distance, priceEstimateResponseMessage.StatusCode)); break; } } } return providerResult; } else { return null; } } catch(Exception e) { return null; } }