コード例 #1
0
        public static RestContentItem ToRest(this ContentItem contentItem, bool includeSchema = true, bool includeNavigationProperties = true)
        {
            RestContentItem restContentItem = new RestContentItem();

            restContentItem.Id = contentItem.Id;
            if (includeSchema)
            {
                restContentItem.Schema = JObject.FromObject(contentItem.Schema.ToRest());
            }
            else
            {
                restContentItem.Schema = contentItem.Schema.Name;
            }
            restContentItem.CreatedAt     = contentItem.CreatedAt;
            restContentItem.ModifiedAt    = contentItem.ModifiedAt;
            restContentItem.PublishedAt   = contentItem.PublishedAt;
            restContentItem.Version       = contentItem.Version;
            restContentItem.SchemaVersion = contentItem.SchemaVersion;

            foreach (var field in contentItem.Fields)
            {
                restContentItem.Fields.Add(field.Key, field.Value.ToRestValue(includeNavigationProperties));
            }

            return(restContentItem);
        }
コード例 #2
0
        public static ContentItem ToModel(this RestContentItem restContentItem, ContentSchema schema)
        {
            if (schema == null)
            {
                if (restContentItem.Schema.Type == JTokenType.String)
                {
                    schema = new ContentSchema(restContentItem.Schema.Value <string>());
                }
                else
                {
                    RestContentSchema restSchema = restContentItem.Schema.ToObject <RestContentSchema>(NewtonJsonExtensions.CreateSerializer());
                    schema = restSchema.ToModel();
                }
            }

            ContentItem contentItem = schema.CreateContentItem();

            contentItem.Id            = restContentItem.Id;
            contentItem.CreatedAt     = restContentItem.CreatedAt;
            contentItem.ModifiedAt    = restContentItem.ModifiedAt;
            contentItem.PublishedAt   = restContentItem.PublishedAt;
            contentItem.Version       = restContentItem.Version;
            contentItem.SchemaVersion = restContentItem.SchemaVersion;

            foreach (var restField in restContentItem.Fields)
            {
                restField.Value.FromRestValue(restField.Key, contentItem, schema);
            }

            return(contentItem);
        }
コード例 #3
0
        public static RestContentItem ToRest(this ContentEmbedded contentItem)
        {
            RestContentItem restContentItem = new RestContentItem();

            restContentItem.Schema = JObject.FromObject(contentItem.Schema.ToRest());

            foreach (var field in contentItem.Fields)
            {
                restContentItem.Fields.Add(field.Key, field.Value.ToRestValue());
            }

            return(restContentItem);
        }
コード例 #4
0
        public async Task InvokeAsync(
            HttpContext context,
            IContentStorage contentStore,
            JsonService jsonService)
        {
            RestContentItem input = await jsonService.Deserialize <RestContentItem>(context.Request.Body);

            ContentItem model = input.ToModel();

            await contentStore.UpdateAsync(model);

            ResourceCreated result = new ResourceCreated()
            {
                Id = input.Id
            };

            string json = jsonService.Serialize(result);

            await context.Response.WriteAsync(json);
        }
コード例 #5
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);
        }
コード例 #6
0
 public static ContentItem ToModel(this RestContentItem restContentItem)
 {
     return(ToModel(restContentItem, null));
 }