Exemplo n.º 1
0
        // Delete A Travellist
        public async System.Threading.Tasks.Task DeleteSelectedTravellist(int id)
        {
            var        taskIdJson = JsonConvert.SerializeObject(id);
            HttpClient httpClient = new HttpClient();
            var        url        = $"http://localhost:5001/api/Travellist/{id}";
            var        res        = await httpClient.DeleteAsync(new Uri(url));

            if (res.IsSuccessStatusCode)
            {
                var deletedTravellist = Travellists.SingleOrDefault((t) => t.Id == id);
                if (deletedTravellist != null)
                {
                    Travellists.Remove(deletedTravellist);
                }
            }
        }
Exemplo n.º 2
0
        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()));
            }
        }
Exemplo n.º 3
0
        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)
            {
            }
        }