public void Insert(IEntity doc, ITicketAutUser user) { if (doc == null) { return; } doc.Id = GetIdDocument(doc.GetType()); var docColl = CollectionsContainer.GetBsonDocumentByType(doc.GetType()) ?? CollectionsContainer.CreateCollection(CollectionsContainer.GetNameCollection(doc.GetType())); if (docColl == null) { throw new KeyNotFoundException("Ошибка при создании коллекции"); } var bson = doc.ToBsonDocument(); bson.RemoveAt(0); var coll = CollectionsContainer.GetMongoCollection(docColl); coll.InsertOneAsync(bson).Wait(); Auditor?.AuditOperation(OperationType.Insert, doc, user); }
public List <T> GetListCollection <T>(FilterDefinition <T> filter) { var docColl = CollectionsContainer.GetBsonDocumentByType(typeof(T)); if (docColl == null) { docColl = CollectionsContainer.CreateCollection(CollectionsContainer.GetNameCollection(typeof(T))); } if (docColl == null) { throw new KeyNotFoundException(); } var coll = CollectionsContainer.GetMongoCollection <T>(docColl); return(coll.FindAsync(filter).Result.ToListAsync().Result); }
public List <T> GetDocuments <T>(List <int> ids) { var docColl = CollectionsContainer.GetBsonDocumentByType(typeof(T)); if (docColl == null) { docColl = CollectionsContainer.CreateCollection(CollectionsContainer.GetNameCollection(typeof(T))); } if (docColl == null) { throw new KeyNotFoundException(); } var coll = CollectionsContainer.GetMongoCollection <T>(docColl); var filter = Builders <T> .Filter.In("Id", ids); return(coll.FindAsync(filter).Result.ToListAsync().Result); }
public void Insert(IHierarchyEntity doc, ITicketAutUser user) { if (doc == null) { return; } doc.Id = GetIdDocument(doc.GetType()); BsonDocument docColl; if (doc.ParentId.HasValue) { docColl = CollectionsContainer.GetBsonDocumentContainsId(doc.GetType(), doc.ParentId.Value); if (docColl == null) { throw new KeyNotFoundException(); } } else { docColl = CollectionsContainer.CreateCollection(CollectionsContainer.GetNameCollection(doc.GetType(), doc.Id.Value)); if (docColl == null) { throw new KeyNotFoundException("Ошибка при создании коллекции"); } } var bson = doc.ToBsonDocument(); bson.RemoveAt(0); var coll = CollectionsContainer.GetMongoCollection(docColl); coll.InsertOneAsync(bson).Wait(); CollectionsContainer.InsertIdCollection(docColl, doc.Id.Value); Auditor?.AuditOperation(OperationType.Insert, doc, user); }
public void InsertBlockDocument(Object doc) { if (doc == null) { return; } var docColl = CollectionsContainer.GetBsonDocumentByType(doc.GetType()) ?? CollectionsContainer.CreateCollection(CollectionsContainer.GetNameCollection(doc.GetType())); if (docColl == null) { throw new KeyNotFoundException("Ошибка при создании коллекции"); } var bson = doc.ToBsonDocument(); bson.RemoveAt(0); var coll = CollectionsContainer.GetMongoCollection(docColl); coll.InsertOneAsync(bson).Wait(); }