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

            RestContentSchema input = await jsonService.Deserialize <RestContentSchema>(context.Request.Body);

            ContentSchema m = input.ToModel();

            await schemaStorage.UpdateAsync(m);
        }
Ejemplo n.º 3
0
        public async Task InvokeAsync(
            HttpContext context,
            ISchemaStorage schemaStorage,
            JsonService jsonService)
        {
            string name = (string)context.GetRouteValue("name");

            RestContentSchema input = await jsonService.Deserialize <RestContentSchema>(context.Request.Body);

            ContentSchema m = input.ToModel();

            await schemaStorage.CreateAsync(m);

            var result = new ResourceCreated()
            {
                Id = m.Id
            };

            string json = jsonService.Serialize(result);

            await context.Response.WriteAsync(json);
        }