public async Task UpdateAsync(ContentItem contentItem)
        {
            contentItem.ApplySchema();

            var drafts = GetMongoCollection(contentItem.Schema.Name);

            contentItem.Validate();

            //update all fields, version
            MongoContentItem result = await drafts.FindOneAndUpdateAsync(
                Builders <MongoContentItem> .Filter.Eq(x => x.Id, contentItem.Id),
                Builders <MongoContentItem> .Update
                .Set(x => x.Fields, contentItem.Fields.ToMongo())
                .Set(x => x.ModifiedAt, DateTimeService.Current())
                .Set(x => x.PublishedAt, null)
                .Set(x => x.SchemaVersion, contentItem.SchemaVersion)
                .Inc(x => x.Version, 1));

            ContentItem content = result.ToModel(contentItem.Schema);

            //execute interceptors
            foreach (IContentInterceptor interceptor in Interceptors)
            {
                await interceptor.OnUpdatedAsync(this, content);
            }
        }
        public async Task CreateAsync(AssetFolder folder)
        {
            folder.CreatedAt  = DateTimeService.Current();
            folder.ModifiedAt = folder.CreatedAt;

            var mongo = folder.ToMongo();

            await AssetFolders.InsertOneAsync(mongo);

            folder.Id = mongo.Id;
        }
        public async Task CreateAsync(Asset asset)
        {
            DateTime now = DateTimeService.Current();

            asset.CreatedAt  = now;
            asset.ModifiedAt = now;

            MongoAsset mongoAsset = asset.ToMongo();

            if (string.IsNullOrWhiteSpace(asset.Slug) == true)
            {
                asset.Slug = asset.Name.ToSlug();
            }

            await Assets.InsertOneAsync(mongoAsset);

            asset.Id = mongoAsset.Id;
        }
        public async Task CreateAsync(ContentSchema schema)
        {
            if (schema.Id == Guid.Empty)
            {
                schema.Id = Guid.NewGuid();
            }

            DateTime now = DateTimeService.Current();

            schema.CreatedAt  = now;
            schema.ModifiedAt = now;

            var mongo = schema.ToMongo();

            await ContentSchemas.InsertOneAsync(mongo);

            schema.Id = mongo.Id;
        }
        public async Task PublishAsync(string schema, Guid id)
        {
            ContentItem contentItem = await GetContentItemAsync(schema, id);

            //execute interceptors
            foreach (IContentInterceptor interceptor in Interceptors)
            {
                await interceptor.OnPublishingAsync(this, contentItem);
            }

            var drafts    = GetMongoCollection(schema, false);
            var published = GetMongoCollection(schema, true);

            //find contentitem
            MongoContentItem found = await drafts.AsQueryable().FirstOrDefaultAsync(x => x.Id == id);

            if (found == null)
            {
                throw new Exception($"content item not found: {schema}/{id}");
            }

            //add contentitem to published collection
            await published.ReplaceOneAsync(
                Builders <MongoContentItem> .Filter.Eq(x => x.Id, id), found, new ReplaceOptions()
            {
                IsUpsert = true
            });

            //update publish date
            await drafts.UpdateOneAsync(
                Builders <MongoContentItem> .Filter.Eq(x => x.Id, id),
                Builders <MongoContentItem> .Update.Set(x => x.PublishedAt, DateTimeService.Current()));

            //refresh contentitem
            contentItem = await GetContentItemAsync(schema, id);

            //execute interceptors
            foreach (IContentInterceptor interceptor in Interceptors)
            {
                await interceptor.OnPublishedAsync(this, contentItem);
            }
        }
        public async Task UpdateAsync(Asset asset)
        {
            //asset.ModifiedAt = DateTime.UtcNow;

            //MongoAsset mongoAsset = asset.ToMongo();

            //await Assets.ReplaceOneAsync(Builders<MongoAsset>.Filter.Where(x => x.Id == asset.Id), mongoAsset);

            await Assets.UpdateOneAsync(
                Builders <MongoAsset> .Filter.Eq(x => x.Id, asset.Id),
                Builders <MongoAsset> .Update
                .Set(x => x.Name, asset.Name)
                .Set(x => x.Slug, asset.Slug.ToSlug())
                .Set(x => x.Alt, asset.Alt)
                .Set(x => x.Description, asset.Description)
                .Set(x => x.Folder, asset.Folder?.Id)
                .Set(x => x.ModifiedAt, DateTimeService.Current())
                .Inc(x => x.Version, 1)
                );
        }
        public async Task CreateAsync(ContentItem contentItem)
        {
            if (contentItem.Id == Guid.Empty)
            {
                contentItem.Id = Guid.NewGuid();
            }

            DateTime now = DateTimeService.Current();

            contentItem.CreatedAt  = now;
            contentItem.ModifiedAt = now;

            var items = GetMongoCollection(contentItem.Schema.Name);

            contentItem.Validate();

            MongoContentItem mongo = contentItem.ToMongo();

            await items.InsertOneAsync(mongo);

            contentItem.Id = mongo.Id;
        }
        public async Task UpdateAsync(ContentSchema entity)
        {
            entity.ModifiedAt = DateTimeService.Current();

            await ContentSchemas.FindOneAndReplaceAsync(Builders <MongoContentSchema> .Filter.Where(x => x.Id == entity.Id), entity.ToMongo());
        }