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; }
public Tuple<long, List<ValidUrl>> FindAndGetAll(int siteId_, string searchField, string searchString_,string searchOperator, string sortField, string sortDirection_, int pageNo_, int records_, bool isSearchRq_) { Tuple<long, List<ValidUrl>> result = null; if (isSearchRq_) { QueryBuilder<ValidUrl> builder = new QueryBuilder<ValidUrl>(); IMongoQuery query = Query.EQ("SiteId",siteId_); switch (searchOperator) { case "cn": throw new NotImplementedException(); break; case "bw": query = builder.And(query, Query.Matches(searchField, new BsonRegularExpression("^" + searchString_, "i"))); break; case "ew": query = builder.And(query, Query.Matches(searchField, new BsonRegularExpression(searchString_ + "$", "i"))); break; case "lt": query = builder.And(query, Query.LT(searchField, searchString_)); break; case "gt": query = builder.And(query, Query.GT(searchField, searchString_)); break; case "ne": query = builder.And(query, Query.NE(searchField, searchString_)); break; case "eq": default: query = builder.And(query, Query.EQ(searchField, searchString_)); break; } var filterDocuments = _db.GetCollection<ValidUrl>(GetCollName(siteId_)).Find(query).AsQueryable().OrderByDescending(y => y.LastModified); //.Skip((pageNo_-1*records_)).Take(records_).ToList<ValidUrl>(); result = new Tuple<long, List<ValidUrl>>(filterDocuments.Count(), filterDocuments.Skip((pageNo_ - 1 * records_)).Take(records_).ToList<ValidUrl>()); } else { var query = (from c in _db.GetCollection<ValidUrl>(GetCollName(siteId_)).AsQueryable() orderby c.LastModified descending select c) .Skip((pageNo_ - 1) * records_) .Take(records_); var list = query.ToList(); result = new Tuple<long, List<ValidUrl>>(GetTotalUrlCount(siteId_), list); } return result; }
public static EntProducto getProducto(String nombre, string tamaño) { string connetionString = "mongodb://*****:*****@ds052408.mongolab.com:52408/juanvaldez"; var mongoClient = new MongoClient(connetionString); var mongoServer = mongoClient.GetServer(); var db = mongoServer.GetDatabase("juanvaldez"); MongoCollection collection = db.GetCollection<EntProducto>("Productos"); EntProducto prod = new EntProducto(); try { var query = new QueryBuilder<EntProducto>(); var queryList = new List<IMongoQuery>(); queryList.Add(Query<EntProducto>.EQ(c => c.Nombre, nombre)); queryList.Add(Query<EntProducto>.EQ(c => c.Tamaño, tamaño)); query.And(queryList); IMongoQuery mongoQuery = query.And(queryList); prod = collection.FindOneAs<EntProducto>(mongoQuery); } catch (Exception e) { prod = null; } return prod; }