Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        public async Task InvokeAsync(
            HttpContext context,
            IContentStorage contentStore,
            ISchemaStorage schemaStorage,
            JsonService jsonService)
        {
            Guid   contentId = Guid.Parse((string)context.GetRouteValue("id"));
            string schema    = (string)context.GetRouteValue("schema");

            ContentItem result = await contentStore.GetContentItemAsync(schema, contentId);

            ContentSchema schemaModel = await schemaStorage.GetContentSchemaAsync(schema);

            result.ApplySchema(schemaModel);

            RestContentItem restModel = result.ToRest();

            string json = jsonService.Serialize(restModel);

            await context.Response.WriteAsync(json);
        }