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

            var docColl = CollectionsContainer.GetBsonDocumentContainsId(doc.GetType(), doc.Id.Value);

            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 RestoreDocument(IHierarchyEntity doc, ITicketAutUser user)
        {
            if (doc == null)
            {
                return;
            }

            BsonDocument docColl = null;

            if (doc.ParentId.HasValue)
            {
                docColl = CollectionsContainer.GetBsonDocumentContainsId(doc.GetType(), doc.ParentId.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 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);
        }