private static async Task<LocationResult> GetLocationsDataAsync(CancellationToken token, string searchTerm = "", double latitude = 0, double longitude = 0, int radius = 0, string workingOn = "", int page = 0, int itemsPerPage = 0) { var locationResult = new LocationResult(); using (var httpClient = new Windows.Web.Http.HttpClient()) { var apiKey = StorageService.LoadSetting("ApiKey"); var apiUrl = StorageService.LoadSetting("ApiUrl"); var channelId = int.Parse(StorageService.LoadSetting("ChannelId")); var countryId = int.Parse(StorageService.LoadSetting("CountryId")); httpClient.DefaultRequestHeaders.Add("Accept-Encoding", "gzip"); httpClient.DefaultRequestHeaders.Add("token", apiKey); httpClient.DefaultRequestHeaders.Add("api-version", "2"); try { var criteria = new LocationListCriteria { ChannelId = channelId, CountryId = countryId, ItemsPerPage = itemsPerPage, Latitude = latitude, Longitude = longitude, Page = page, Radius = radius, SearchTerm = searchTerm, WorkingOn = workingOn }; var url = apiUrl + "/api/locations/workspace?" + JsonConvert.SerializeObject(criteria); using (var httpResponse = await httpClient.GetAsync(new Uri(url)).AsTask(token)) { string json = await httpResponse.Content.ReadAsStringAsync().AsTask(token); json = json.Replace("<br>", Environment.NewLine); if (string.IsNullOrEmpty(searchTerm)) { await FileHelper.SaveStringToLocalFile("locations.json", json); } locationResult = JsonConvert.DeserializeObject<LocationResult>(json); } } catch (Exception) { } } return locationResult; }
public static async Task GetLocationRecommendationsAsync(CancellationToken token, ObservableCollection<Location> locationList, double latitude = 0, double longitude = 0, int radius = 0, string workingOn = "", int page = 0, int itemsPerPage = 0) { var locationResult = new LocationResult(); using (var httpClient = new Windows.Web.Http.HttpClient()) { var apiKey = StorageService.LoadSetting("ApiKey"); var apiUrl = StorageService.LoadSetting("ApiUrl"); var channelId = int.Parse(StorageService.LoadSetting("ChannelId")); var countryId = int.Parse(StorageService.LoadSetting("CountryId")); httpClient.DefaultRequestHeaders.Add("Accept-Encoding", "gzip"); httpClient.DefaultRequestHeaders.Add("token", apiKey); httpClient.DefaultRequestHeaders.Add("api-version", "2"); try { var criteria = new LocationListCriteria { ItemsPerPage = itemsPerPage, Latitude = latitude, Longitude = longitude, Page = page, Radius = radius, WorkingOn = workingOn }; var url = apiUrl + "/api/locations/recommendation?" + JsonConvert.SerializeObject(criteria); using (var httpResponse = await httpClient.GetAsync(new Uri(url)).AsTask(token)) { string json = await httpResponse.Content.ReadAsStringAsync().AsTask(token); json = json.Replace("<br>", Environment.NewLine); locationResult = JsonConvert.DeserializeObject<LocationResult>(json); } } catch (Exception) { } } foreach (var location in locationResult.Results) { locationList.Add(location); } }