Exemplo n.º 1
0
        public static async Task <string> Insertar(UsuarioModel usuario)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var uri = new Uri(URLAPI.Usuario() + "InsertarUsuario");

                    var json = JsonConvert.SerializeObject(
                        new {
                        Usuario          = usuario.Usuario,
                        Contrasenna      = usuario.Contrasenna,
                        Estado           = usuario.Estado,
                        Usuario_Creacion = usuario.Usuario_Creacion,
                        Fecha_Creacion   = usuario.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 <UsuarioModel> > SeleccionarTodos()
        {
            // string json = "\"[{\\\"Usuario\\\":\\\"Admin\\\",\\\"Contrasenna\\\":\\\"admin\\\",\\\"Estado\\\":1,\\\"Usuario_Creacion\\\":\\\"caro\\\",\\\"Fecha_Creacion\\\":\\\"2018-01-02T20:23:24\\\"},{\\\"Usuario\\\":\\\"c\\\",\\\"Contrasenna\\\":\\\"c\\\",\\\"Estado\\\":1,\\\"Usuario_Creacion\\\":\\\"caro\\\",\\\"Fecha_Creacion\\\":\\\"2017-12-27T20:39:20\\\"},{\\\"Usuario\\\":\\\"Carolina\\\",\\\"Contrasenna\\\":\\\"a\\\",\\\"Estado\\\":1,\\\"Usuario_Creacion\\\":\\\"Admin\\\",\\\"Fecha_Creacion\\\":\\\"2017-12-14T20:31:45\\\"},{\\\"Usuario\\\":\\\"Carolina1\\\",\\\"Contrasenna\\\":\\\"a\\\",\\\"Estado\\\":1,\\\"Usuario_Creacion\\\":\\\"Caro\\\",\\\"Fecha_Creacion\\\":\\\"2017-12-27T20:40:53\\\"},{\\\"Usuario\\\":\\\"Carolina1k\\\",\\\"Contrasenna\\\":\\\"a\\\",\\\"Estado\\\":1,\\\"Usuario_Creacion\\\":\\\"Caro\\\",\\\"Fecha_Creacion\\\":\\\"2017-12-27T20:48:45\\\"}]\"";

            //UsuarioModel[] jsonObject = JsonConvert.DeserializeObject<UsuarioModel[]>(json);

            //ObservableCollection<UsuarioModel> LstUsuarios = new ObservableCollection<UsuarioModel>(jsonObject.ToList());
            //return;

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var uri = new Uri(URLAPI.Usuario() + "SeleccionarUsuarios");

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

                    return(new ObservableCollection <UsuarioModel>(JsonConvert.DeserializeObject <UsuarioModel[]>(resultado).ToList()));
                }
            }
            catch (WebException wex)
            {
                throw wex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        public static async Task <string> Autenticar(UsuarioModel usuario)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var uri = new Uri(URLAPI.Usuario() + "autenticar"); //Direccion de mi API

                    //var json = JsonConvert.SerializeObject(new { Usuario = usuario.Usuario, Contrasenna = usuario.Contrasenna, Estado = usuario.Estado, Usuario_Creacion = usuario.Usuario_Creacion }); //Esto es un string
                    var json = JsonConvert.SerializeObject(
                        new {
                        Usuario     = usuario.Usuario,
                        Contrasenna = usuario.Contrasenna
                    }
                        );                                     //Esto es un string

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

                    //HttpResponseMessage response = await client.PostAsync(uri, content).ConfigureAwait(false); //Esto se puede obviar ConfigureAwait(false)
                    HttpResponseMessage response = client.PostAsync(uri, content).Result;
                    string resultado             = await response.Content.ReadAsStringAsync();

                    resultado = JsonConvert.DeserializeObject <string>(resultado);
                    //UsuarioModel usuario = JsonConvert.DeserializeObject<UsuarioModel>(ans)

                    return(resultado);
                }


                //var request = (HttpWebRequest)WebRequest.Create("https://152b4592.ngrok.io/api/prueba");

                //var json = JsonConvert.SerializeObject(new { Usuario = usuario.Usuario, Contrasenna = usuario.Contrasenna });
                //var data = Encoding.UTF8.GetBytes(json);

                //request.Method = "POST";
                //request.ContentType = "application/json";
                //request.ContentLength = data.Length;

                //using (var stream = request.GetRequestStream())
                //{
                //    stream.Write(data, 0, data.Length);
                //}

                //var response = (HttpWebResponse)request.GetResponse();

                //var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

                return("");
            }
            catch (WebException wex)
            {
                throw wex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 4
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.º 5
0
        public static async Task <string> Insertar(PedidoLineaModel pedidoLinea)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var uri = new Uri(URLAPI.PedidoLinea() + "InsertarPedidoLinea");

                    var json = JsonConvert.SerializeObject(
                        new
                    {
                        Id_Pedido       = pedidoLinea.Id_Pedido,
                        Id_Producto     = pedidoLinea.Id_Producto,
                        Desc_Producto   = pedidoLinea.Desc_Producto,
                        Imagen          = pedidoLinea.Imagen,
                        Seleccionado    = pedidoLinea.Seleccionado,
                        Cant_Solicitada = pedidoLinea.Cant_Solicitada,
                        Precio_Unitario = pedidoLinea.Precio_Unitario,
                        Subtotal        = pedidoLinea.Subtotal
                    }
                        );

                    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.º 6
0
        public static async Task <string> Actualizar(ClienteModel cliente)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var uri = new Uri(URLAPI.Cliente() + "ActualizarCliente");

                    var json = JsonConvert.SerializeObject(
                        new
                    {
                        Cedula           = cliente.Cedula,
                        Nombre           = cliente.Nombre,
                        Telefono         = cliente.Telefono,
                        Email            = cliente.Email,
                        Estado           = cliente.Estado,
                        Direccion        = cliente.Direccion,
                        Usuario_Creacion = cliente.Usuario_Creacion,
                        Fecha_Creacion   = cliente.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.º 7
0
        public static async Task <string> Confirmar(PedidoModel pedido)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var uri = new Uri(URLAPI.Pedido() + "ConfirmarPedido");

                    var json = JsonConvert.SerializeObject(
                        new
                    {
                        Id_Pedido            = pedido.Id_Pedido,
                        Fecha                = pedido.Fecha,
                        Cliente              = pedido.Cliente,
                        TotalPedido          = pedido.TotalPedido,
                        Estado               = pedido.Estado,
                        Usuario_Confirmacion = pedido.Usuario_Confirmacion,
                        Usuario_Creacion     = pedido.Usuario_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.º 8
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.º 9
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;
            }
        }
Exemplo n.º 10
0
        public static async Task <string> Eliminar(string pedido)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var uri = new Uri(URLAPI.Pedido() + "EliminarPedido?pedido=" + pedido);

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

                    return(resultado);
                }
            }
            catch (WebException wex)
            {
                throw wex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 11
0
        public static async Task <ObservableCollection <PedidoLineaModel> > SeleccionarPorPedido(string pedido)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var uri = new Uri(URLAPI.PedidoLinea() + "SeleccionarPedidoLinea?codigo=" + pedido);

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

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