public bool InsertCliente(Cliente c)
        {
            MySqlConnection con = new MySqlConnection(_stringConnection);
            con.Open();

            string sql = "INSERT INTO cliente(nombre, telefono) VALUES (@nombre, @telefono)";
            MySqlCommand cmd = new MySqlCommand(sql, con);
            cmd.Parameters.Add("@nombre", MySqlDbType.VarChar).Value = c.Nombre;
            cmd.Parameters.Add("@telefono", MySqlDbType.VarChar).Value = c.Telefono;

            int res = cmd.ExecuteNonQuery();
            con.Close();

            return (res == 1);
        }
        // POST    /Clientes/Cliente    { Nombre:"nombre", Telefono:123456789 }
        // PUT     /Clientes/Cliente/3  { Id:3, Nombre:"nombre", Telefono:123456789 }
        // GET     /Clientes/Cliente/3
        // DELETE  /Clientes/Cliente/3
        public JsonResult Cliente(int? id, Cliente item)
        {
            switch (Request.HttpMethod)
            {
                case "POST":
                    return Json(clientesManager.InsertCliente(item));
                case "PUT":
                    return Json(clientesManager.UpdateCliente(item));
                case "GET":
                    return Json(clientesManager.GetCliente(id.GetValueOrDefault()),
                                JsonRequestBehavior.AllowGet);
                case "DELETE":
                    return Json(clientesManager.DeleteCliente(id.GetValueOrDefault()));
            }

            return Json(new { Error = true, Message = "OperaciĆ³n HTTP desconocida" });
        }
        public Cliente GetCliente(int id)
        {
            Cliente cli = null;
            MySqlConnection con = new MySqlConnection(_stringConnection);
            con.Open();
            string sql = "SELECT nombre, telefono FROM cliente WHERE id = @id";

            MySqlCommand cmd = new MySqlCommand(sql, con);

            cmd.Parameters.Add("@id", MySqlDbType.VarChar).Value = id;

            MySqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                cli = new Cliente();
                cli.Id = id;
                cli.Nombre = reader.GetString(0);
                cli.Telefono = reader.GetString(1);
            }
            reader.Close();
            return cli;
        }
        public List<Cliente> RetrieveAllClientes()
        {
            List<Cliente> lista = new List<Cliente>();
            MySqlConnection con = new MySqlConnection(_stringConnection);
            con.Open();

            string sql = "SELECT id, nombre, telefono FROM cliente";
            MySqlCommand cmd = new MySqlCommand(sql, con);

            MySqlDataReader r = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

            while (r.Read())
            {
                Cliente c = new Cliente();
                c.Id = r.GetInt32(0);
                c.Nombre = r.GetString(1);
                c.Telefono = r.GetString(2);

                lista.Add(c);
            }
            r.Close();
            return lista;
        }
        public bool UpdateCliente(Cliente cli)
        {
            MySqlConnection con = new MySqlConnection(_stringConnection);

            con.Open();

            string sql = "UPDATE cliente SET nombre = @nombre, telefono = @telefono WHERE id = @id";

            MySqlCommand cmd = new MySqlCommand(sql, con);

            cmd.Parameters.Add("@nombre", MySqlDbType.VarChar).Value = cli.Nombre;
            cmd.Parameters.Add("@telefono", MySqlDbType.VarChar).Value = cli.Telefono;
            cmd.Parameters.Add("@id", MySqlDbType.Int32).Value = cli.Id;

            int res = cmd.ExecuteNonQuery();
            con.Close();
            return (res == 1);
        }