public Entities.ResponseCollection <BsonDocument> GetPrimi20Documenti(string collezione) { Entities.ResponseCollection <BsonDocument> response = new Entities.ResponseCollection <BsonDocument>(); try { if (mongoClientSettings == null || mongoClient == null) { Initialize(); } IMongoDatabase myDB = mongoClient.GetDatabase(DatabaseName.BAM_Affinati); IMongoCollection <BsonDocument> collection = myDB.GetCollection <BsonDocument>(collezione); response.collection = collection.Aggregate() .Limit(5) .Project(new BsonDocument { { DatabaseColumnsName._id, 0 }, { DatabaseColumnsName.DDATA, 1 }, { DatabaseColumnsName.SFILIALE, 1 }, { DatabaseColumnsName.SSEGNO, 1 }, { DatabaseColumnsName.SCAUSALE, 1 }, { DatabaseColumnsName.SDESCRIZIONECAUSALE, 1 }, { DatabaseColumnsName.SRAPPORTO, 1 } }).ToList(); if (response.collection.Count == 0) { throw new Exception("Empty list"); } } catch (Exception ex) { response.result.AddError(ex); } return(response); }
public Entities.ResponseCollection <BsonDocument> GetCollection() { Entities.ResponseCollection <BsonDocument> response = new Entities.ResponseCollection <BsonDocument>(); try { object dictionaryValue; if (dictionaryCollection.TryGetValue(DictionaryCollezioniKey.Collezioni, out dictionaryValue)) { response.collection = (List <BsonDocument>)dictionaryValue; } else { if (mongoClientSettings == null || mongoClient == null) { Initialize(); } IMongoDatabase myDB = mongoClient.GetDatabase(DatabaseName.BAM_Affinati); List <BsonDocument> collection = myDB.ListCollections().ToList(); response.collection = collection; dictionaryCollection.Add(DictionaryCollezioniKey.Collezioni, response.collection); } } catch (Exception ex) { response.result.AddError(ex); } return(response); }
public Entities.ResponseCollection <BsonDocument> GetFiliali() { Entities.ResponseCollection <BsonDocument> response = new Entities.ResponseCollection <BsonDocument>(); try { object dictionaryValue; if (dictionaryFiliali.TryGetValue(DictionaryFilialiliKey.Filiali, out dictionaryValue)) { response.collection = (List <BsonDocument>)dictionaryValue; } else { if (mongoClientSettings == null || mongoClient == null) { Initialize(); } IMongoDatabase myDB = mongoClient.GetDatabase(DatabaseName.BAM); IMongoCollection <BsonDocument> collection = myDB.GetCollection <BsonDocument>(CollectionsName._Movimenti_Filiali_OrderedCount); response.collection = collection.Aggregate() .Sort(new BsonDocument { { DatabaseColumnsName.Count, -1 } }) .Limit(20) .Project(new BsonDocument { { DatabaseColumnsName._id, 0 }, { DatabaseColumnsName.NFILIALE, "$" + DatabaseColumnsName.NFILIALE }, { DatabaseColumnsName.Sfiliale, "$" + DatabaseColumnsName.SFILIALE } }) .ToList(); dictionaryFiliali.Add(DictionaryFilialiliKey.Filiali, response.collection); } } catch (Exception ex) { response.result.AddError(ex); } return(response); }
public Entities.ResponseCollection <BsonDocument> GetPrime20Causali() { Entities.ResponseCollection <BsonDocument> response = new Entities.ResponseCollection <BsonDocument>(); try { object dictionaryValue; if (dictionaryCausali.TryGetValue(DictionaryCausaliKey.Prime20Causali, out dictionaryValue)) { response.collection = (List <BsonDocument>)dictionaryValue; } else { if (mongoClientSettings == null || mongoClient == null) { Initialize(); } //IMongoDatabase myDB = mongoClient.GetDatabase(DatabaseName.BAM); //IMongoCollection<BsonDocument> collection = myDB.GetCollection<BsonDocument>(CollectionsName.Causali_Movimenti); //response.collection = collection.Aggregate() // .Group(new BsonDocument { { DatabaseColumnsName._id, "$"+DatabaseColumnsName.SCAUSALE }, { DatabaseColumnsName.Count , new BsonDocument("$sum", 1) } }) // .Sort(new BsonDocument { { DatabaseColumnsName.Count, -1 } }) // .Limit(20) // .Lookup(CollectionsName.Causali, DatabaseColumnsName._id, DatabaseColumnsName.SCAUSALE, DatabaseColumnsName.Dettagli) // .Unwind(DatabaseColumnsName.Dettagli) // .Group(new BsonDocument { { DatabaseColumnsName._id, new BsonDocument { // { DatabaseColumnsName.Causale, "$" + DatabaseColumnsName.Dettagli + "." + DatabaseColumnsName.SCAUSALE } // , { DatabaseColumnsName.DescrizioneCausale ,"$" + DatabaseColumnsName.Dettagli + "." + DatabaseColumnsName.SDESCRIZIONECAUSALE } } } // , { DatabaseColumnsName.Count , new BsonDocument("$sum", 1) } }) // .Project(new BsonDocument { { DatabaseColumnsName._id, 0 }, { DatabaseColumnsName.Causale, "$" + DatabaseColumnsName._id + "." + DatabaseColumnsName.Causale } // , { DatabaseColumnsName.DescrizioneCausale ,"$" + DatabaseColumnsName._id + "." + DatabaseColumnsName.DescrizioneCausale } }) // .ToList(); IMongoDatabase myDB = mongoClient.GetDatabase(DatabaseName.BAM); IMongoCollection <BsonDocument> collection = myDB.GetCollection <BsonDocument>(CollectionsName._Movimenti_Causali_OrderedCount); response.collection = collection.Aggregate() .Sort(new BsonDocument { { DatabaseColumnsName.Count, -1 } }) .Limit(20) .Lookup(CollectionsName.Causali, DatabaseColumnsName._id, DatabaseColumnsName.SCAUSALE, DatabaseColumnsName.Dettagli) .Unwind(DatabaseColumnsName.Dettagli) .Group(new BsonDocument { { DatabaseColumnsName._id, new BsonDocument { { DatabaseColumnsName.Causale, "$" + DatabaseColumnsName.Dettagli + "." + DatabaseColumnsName.SCAUSALE } , { DatabaseColumnsName.DescrizioneCausale, "$" + DatabaseColumnsName.Dettagli + "." + DatabaseColumnsName.SDESCRIZIONECAUSALE } } } , { DatabaseColumnsName.Count, new BsonDocument("$sum", 1) } }) .Project(new BsonDocument { { DatabaseColumnsName._id, 0 }, { DatabaseColumnsName.Causale, "$" + DatabaseColumnsName._id + "." + DatabaseColumnsName.Causale } , { DatabaseColumnsName.DescrizioneCausale, "$" + DatabaseColumnsName._id + "." + DatabaseColumnsName.DescrizioneCausale } }) .ToList(); if (response.collection.Count == 0) { throw new Exception("Empty list"); } dictionaryCausali.Add(DictionaryCausaliKey.Prime20Causali, response.collection); } } catch (Exception ex) { response.result.AddError(ex); } return(response); }