Exemplo n.º 1
0
        internal async static Task AlterarTarefa(Tarefa model)
        {
            var client = new HttpClient
            {
                BaseAddress = new Uri(App.BaseUrl)
            };

            client.DefaultRequestHeaders.Add("Accept", "application/json");
            client.DefaultRequestHeaders.Add("Authorization", "bearer " + MyLocalStorage.GetFromLocalStorage("token"));

            var json = JsonConvert.SerializeObject(model);

            var dados = new StringContent(
                json, Encoding.UTF8, "application/json"
                );

            var response = await client.PutAsync("api/Tarefa/" + model.Id, dados);

            try
            {
                response.EnsureSuccessStatusCode();
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public static async Task <List <Tarefa> > ListarAsync()
        {
            var client = new HttpClient {
                BaseAddress = new Uri(App.BaseUrl)
            };

            client.DefaultRequestHeaders.Add("Accept", "application/jason");
            client.DefaultRequestHeaders.Add("Authorization", "bearer " + MyLocalStorage.GetFromLocalStorage("token"));

            var response = await client.GetAsync("api/Tarefa");

            try
            {
                response.EnsureSuccessStatusCode();

                var json = await response.Content.ReadAsStringAsync();

                var lista = JsonConvert.DeserializeObject <List <Tarefa> >(json);

                return(lista);
            }
            catch (Exception)
            {
                throw;
            }
        }