private async void LoadParkHouses() { List<Parkhouse> tempParkhouses = await repParkhouses.GetParkHouses(); foreach(Parkhouse tempParkhous in tempParkhouses) { Parkhouses.Add(tempParkhous); } SelectedParkhouse = Parkhouses[0]; }
private void SelectParkHouse(int ID) { foreach(Parkhouse parkhouse in Parkhouses) { if(parkhouse.ID == ID) { SelectedParkhouse = parkhouse; return; } } }
public async Task<List<Parkhouse>> GetParkHouses() { List<Parkhouse> parkhouses = new List<Parkhouse>(); using (HttpClient client = new HttpClient()) { HttpResponseMessage response = await client.GetAsync("http://datatank.stad.gent/4/mobiliteit/bezettingparkingsrealtime.json"); if(response.IsSuccessStatusCode) { String json = await response.Content.ReadAsStringAsync(); dynamic result = JsonConvert.DeserializeObject(json); for(int i = 0; i < result.Count; i++) { Parkhouse parkhouse = new Parkhouse() { ID = result[i].id, Name = result[i].name, Description = result[i].description, Latitude = result[i].latitude, Longitude = result[i].longitude, Address = result[i].address, ContactInfo = result[i].contactInfo }; if(result[i].parkingStatus != null) { parkhouse.AvailableCapacity = result[i].parkingStatus.availableCapacity; parkhouse.TotalCapacity = result[i].parkingStatus.totalCapacity; } parkhouses.Add(parkhouse); } } } return parkhouses; }