public async System.Threading.Tasks.Task AddNewTravellist(Travellist tl /*, string country, string street, string houseNr, DateTime? dateLeave, DateTime? dateBack*/) { //var travellist = new Travellist() { Name = name, Country = country, Street = street, HouseNr = houseNr, DateLeave = dateLeave, DateBack = dateBack }; var test = new Travellist() { Name = tl.Name, Country = tl.Country, Street = "street", HouseNr = "nr", DateLeave = tl.DateLeave, DateBack = tl.DateBack }; var travellistJson = JsonConvert.SerializeObject(test); HttpClient httpClient = new HttpClient(); var res = await httpClient.PostAsync(new Uri("http://localhost:5001/api/Travellist"), new HttpStringContent(travellistJson, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json")); if (res.IsSuccessStatusCode) { Travellists.Add(JsonConvert.DeserializeObject <Travellist>(res.Content.ToString())); } }
private async void loadTravellists() { //var travelLists = User.Travellists; try { HttpClient httpClient = new HttpClient(); var token = Globals.LoggedInUser.access_token; httpClient.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("Bearer", token); var response = await httpClient.GetStringAsync(new Uri("http://localhost:5001/api/Travellist/User")); var travelLists = JsonConvert.DeserializeObject <IList <Travellist> >(response); foreach (var tl in travelLists) { Travellists.Add(tl); } } catch (Exception) { } }