public void Update(IEntity doc, ITicketAutUser user)
        {
            if (doc?.Id == null)
            {
                return;
            }

            var docColl = CollectionsContainer.GetBsonDocumentByType(doc.GetType());

            if (docColl == null)
            {
                throw new KeyNotFoundException();
            }

            var bson = doc.ToBsonDocument();

            bson.RemoveAt(0);

            var coll   = CollectionsContainer.GetMongoCollection(docColl);
            var filter = Builders <BsonDocument> .Filter.Eq("_id", doc.Id);

            coll.ReplaceOneAsync(filter, bson);

            Auditor?.AuditOperation(OperationType.Update, doc, user);
        }
        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 void Delete(Type docType, FilterDefinition <BsonDocument> filter)
        {
            var docColl = CollectionsContainer.GetBsonDocumentByType(docType);

            if (docColl == null)
            {
                throw new KeyNotFoundException();
            }

            var coll = CollectionsContainer.GetMongoCollection(docColl);

            coll.DeleteOneAsync(filter);

            //Auditor?.AuditOperation(OperationType.Delete, 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 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();
        }