/// <summary> /// This function generates a query, and returns all coincidences where key = value /// </summary> /// <param name="key"> /// The collection's key value in the db /// </param> /// <param name="value"> /// The collection's value in the db /// </param> /// <author> /// Luis Gonzalo Quijada Romero /// </author> /// <returns></returns> public String get(String key, String value) { JoinCollections Join = new JoinCollections(); var query = Query.And(Query.EQ(key, value)); //creating the query Join.Select("ReferenceObjects"); Join.Join("Categories", "parentCategory", "_id", "name => categoryName"); Join.Join("Users", "Creator", "_id", "name => Creator"); var result = Join.Find(query); return(result); }
public string GetMovementsTable(JObject options) { //Query needed to get the result IMongoQuery query = null, query2; List <IMongoQuery> listqueries = new List <IMongoQuery>(); List <IMongoQuery> listqueries2 = new List <IMongoQuery>(); long dateinit = 0; DateTime fecha = new DateTime(); int cantidad; if (options["type"].ToString() != "summary") { int.TryParse(options["date"][0].ToString(), out cantidad); if (options["date"][1].ToString() == "minutes") { fecha = DateTime.Now.AddMinutes(-cantidad); } if (options["date"][1].ToString() == "hours") { fecha = DateTime.Now.AddHours(-cantidad); } if (options["date"][1].ToString() == "days") { fecha = DateTime.Now.AddDays(-cantidad); } string cad1 = fecha.ToString("yyyyMMddhhmmss"); long.TryParse(cad1, out dateinit); } JObject objfilter = JsonConvert.DeserializeObject <JObject>(options["filters"].ToString()); JArray filters = JsonConvert.DeserializeObject <JArray>(objfilter["modules"].ToString()); JArray valores = new JArray(); JObject moves = new JObject(); moves["MovementProfiles"] = "movement"; moves["Locations"] = "location"; moves["Users"] = "Creator"; moves["MovementStatus"] = "status"; foreach (JObject filter in filters) { listqueries2.Clear(); valores = JsonConvert.DeserializeObject <JArray>(filter["v"].ToString()); if (valores.Count == 0) { continue; } foreach (String val in valores) { listqueries2.Add(Query.EQ(moves[filter["mod"].ToString()].ToString(), val)); } query2 = Query.Or(listqueries2); listqueries.Add(query2); } if (options["type"].ToString() != "summary") { listqueries.Add(Query.GTE("CreatedTimeStamp", dateinit)); } if (listqueries.Count > 0) { query = Query.And(listqueries); } JoinCollections Join = new JoinCollections(); Join = Join.Select("Demand"); foreach (JObject filter in filters) { if (objfilter["group"].ToString() == moves[filter["mod"].ToString()].ToString() || moves[filter["mod"].ToString()].ToString() == "status" ) { continue; } Join = Join.Join(filter["mod"].ToString(), moves[filter["mod"].ToString()].ToString(), "_id", "name => " + moves[filter["mod"].ToString()].ToString()); } string groupMod = ""; if (objfilter["group"].ToString() != "status") { foreach (KeyValuePair <String, JToken> token in moves) { if (token.Value.ToString() == objfilter["group"].ToString()) { groupMod = token.Key.ToString(); } } Join = Join.Join(groupMod, objfilter["group"].ToString(), "_id", "name => " + moves[groupMod].ToString()); } return(Join.Find(query)); }
public string GetObjectsTable(JObject options) { //Query needed to get the result IMongoQuery query = null, query2; List <IMongoQuery> listqueries = new List <IMongoQuery>(); List <IMongoQuery> listqueries2 = new List <IMongoQuery>(); long dateinit = 0; DateTime fecha = new DateTime(); int cantidad; if (options["type"].ToString() != "summary") { int.TryParse(options["date"][0].ToString(), out cantidad); if (options["date"][1].ToString() == "minutes") { fecha = DateTime.Now.AddMinutes(-cantidad); } if (options["date"][1].ToString() == "hours") { fecha = DateTime.Now.AddHours(-cantidad); } if (options["date"][1].ToString() == "days") { fecha = DateTime.Now.AddDays(-cantidad); } string cad1 = fecha.ToString("yyyyMMddhhmmss"); long.TryParse(cad1, out dateinit); } JObject objfilter = JsonConvert.DeserializeObject <JObject>(options["filters"].ToString()); JArray filters = JsonConvert.DeserializeObject <JArray>(objfilter["modules"].ToString()); JArray valores = new JArray(); JObject ObjectsReal = new JObject(); ObjectsReal["Locations"] = "location"; ObjectsReal["ReferenceObjects"] = "objectReference"; ObjectsReal["Users"] = "userid"; MongoModel profdb = new MongoModel("LocationProfiles"); MongoModel locationdb = new MongoModel("Locations"); foreach (JObject filter in filters) { listqueries2.Clear(); valores = JsonConvert.DeserializeObject <JArray>(filter["v"].ToString()); if (valores.Count == 0) { continue; } foreach (String val in valores) { try { JObject location = JsonConvert.DeserializeObject <JObject>(locationdb.GetRow(val)); JObject profid = JsonConvert.DeserializeObject <JObject>(profdb.GetRow(location["profileId"].ToString())); if (profid["name"].ToString() != "Sub-Ubicaciones") { List <string> sublocationslist = sublocations(val, profid["name"].ToString()); foreach (string sub in sublocationslist) { try { listqueries2.Add(Query.EQ(ObjectsReal[filter["mod"].ToString()].ToString(), sub)); } catch { } } } } catch { } listqueries2.Add(Query.EQ(ObjectsReal[filter["mod"].ToString()].ToString(), val)); } query2 = Query.Or(listqueries2); listqueries.Add(query2); } if (options["type"].ToString() != "summary") { listqueries.Add(Query.GTE("CreatedTimeStamp", dateinit)); } if (listqueries.Count > 0) { query = Query.And(listqueries); } JoinCollections Join = new JoinCollections(); Join = Join.Select("ObjectReal"); foreach (JObject filter in filters) { if (objfilter["group"].ToString() == ObjectsReal[filter["mod"].ToString()].ToString()) { continue; } Join = Join.Join(filter["mod"].ToString(), ObjectsReal[filter["mod"].ToString()].ToString(), "_id", "name => " + ObjectsReal[filter["mod"].ToString()].ToString()); } string groupMod = ""; foreach (KeyValuePair <String, JToken> token in ObjectsReal) { if (token.Value.ToString() == objfilter["group"].ToString()) { groupMod = token.Key.ToString(); } } Join = Join.Join(groupMod, objfilter["group"].ToString(), "_id", "name => " + ObjectsReal[groupMod].ToString()); return(Join.Find(query)); }