private async void btnAgregar_Click(object sender, RoutedEventArgs e)
        {
            Categor p = new Categor();

            p.descripcion     = txtCategoria.Text;
            p.precioCategoria = txtPrecio.Text;


            await Categor.AgregarCategoria(p); //No olvidar el await

            ObtenerDatos();
        }
Esempio n. 2
0
        public static async Task <bool> AgregarCategoria(Categor c)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:63050/");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage respuesta = await client.PostAsJsonAsync("api/Categoria", c);

                return(respuesta.IsSuccessStatusCode);
            }
        }
        private async void ObtenerDatos()
        {
            List <Categor> lista = await Categor.ObtenerTodos(); //No olvidar el await

            lstCategoria.ItemsSource = lista;
        }