Esempio n. 1
0
        public static EntCliente getCliente(string Usuario, String Password)
        {
            const string connectionString = "mongodb://*****:*****@ds052408.mongolab.com:52408/juanvaldez";
            var mongoClient = new MongoClient(connectionString);
            var mongoServer = mongoClient.GetServer();
            var db = mongoServer.GetDatabase("juanvaldez");
            MongoCollection collection = db.GetCollection<EntCliente>("Clientes");
            EntCliente persona = new EntCliente();
            try
            {
                var query = new QueryBuilder<EntCliente>();
                var queryList = new List<IMongoQuery>();
                queryList.Add(Query<EntCliente>.EQ(c => c.Usuario, Usuario));
                queryList.Add(Query<EntCliente>.EQ(c => c.Password, Password));
                query.And(queryList);
                IMongoQuery mongoQuery = query.And(queryList);

                persona = collection.FindOneAs<EntCliente>(mongoQuery);
            }
            catch (Exception e)
            {
                persona = null;
            }
            return persona;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (!TextBox1.Text.Equals("") && !TextBox2.Text.Equals("") && !TextBox3.Text.Equals("") && !TextBox4.Text.Equals(""))
            {
                const string connectionString = "mongodb://*****:*****@ds052408.mongolab.com:52408/juanvaldez";
                var mongoClient = new MongoClient(connectionString);
                var mongoServer = mongoClient.GetServer();
                var db = mongoServer.GetDatabase("juanvaldez");
                MongoCollection collection = db.GetCollection<EntCliente>("Clientes");
                EntCliente persona = new EntCliente();
                persona.Nombre = TextBox1.Text;
                persona.Usuario = TextBox2.Text;
                persona.Password = TextBox3.Text;
                persona.NoTarjeta = TextBox4.Text;
                collection.Insert(persona);
            }
            else {

            }
        }