Exemplo n.º 1
0
        public static async Task <string> Eliminar(ProductoModel producto)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var uri = new Uri(URLAPI.Producto() + "EliminarProducto");

                    var json = JsonConvert.SerializeObject(
                        new
                    {
                        Codigo             = producto.Codigo,
                        Descripcion        = producto.Descripcion,
                        Precio             = producto.Precio,
                        CantidadInventario = producto.CantidadInventario,
                        Estado             = producto.Estado,
                        Observaciones      = producto.Observaciones,
                        Imagen             = producto.Imagen,
                        Usuario_Creacion   = producto.Usuario_Creacion,
                        Fecha_Creacion     = producto.Fecha_Creacion
                    }
                        );

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

                    HttpResponseMessage response = client.PostAsync(uri, content).Result;
                    string resultado             = await response.Content.ReadAsStringAsync();

                    return(resultado);
                }
            }
            catch (WebException wex)
            {
                throw wex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public static async Task <ObservableCollection <ProductoModel> > SeleccionarActivos()
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var uri = new Uri(URLAPI.Producto() + "SeleccionarProductosActivos");

                    HttpResponseMessage response = client.GetAsync(uri).Result;
                    string resultado             = await response.Content.ReadAsStringAsync();

                    return(new ObservableCollection <ProductoModel>(JsonConvert.DeserializeObject <ProductoModel[]>(resultado).ToList()));
                }
            }
            catch (WebException wex)
            {
                throw wex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        public static async Task <ProductoModel> SeleccionarPorCodigo(string codigo)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var uri = new Uri(URLAPI.Producto() + "SeleccionarProductosPorCodigo");

                    HttpResponseMessage response = client.GetAsync(uri).Result;
                    string resultado             = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <ProductoModel>(resultado));
                }
            }
            catch (WebException wex)
            {
                throw wex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }