예제 #1
0
        public ContentSchemaBuilder(ISchemaStorage schemaStorage)
        {
            Storage = schemaStorage;

            _schemaByName = new Dictionary <string, Type>();
            _schema       = new Dictionary <Type, ContentSchema>();
        }
        public async Task InvokeAsync(
            HttpContext context,
            ISchemaStorage schemaStorage,
            JsonService jsonService)
        {
            ContentSchema schema;

            if (context.GetRouteValue("id") is string)
            {
                Guid id = Guid.Parse((string)context.GetRouteValue("id"));

                schema = await schemaStorage.GetContentSchemaAsync(id);
            }
            else
            {
                string name = (string)context.GetRouteValue("name");

                schema = await schemaStorage.GetContentSchemaAsync(name);
            }

            RestContentSchema restSchema = schema.ToRest();

            string json = jsonService.Serialize(restSchema);

            await context.Response.WriteAsync(json);
        }
        public async Task InvokeAsync(
            HttpContext context,
            IContentStorage contentStore,
            ISchemaStorage schemaStorage,
            JsonService jsonService)
        {
            string schema = (string)context.GetRouteValue("schema");

            QueryParameters queryParameters = await jsonService.Deserialize <QueryParameters>(context.Request.Body);

            ContentSchema schemaModel = await schemaStorage.GetContentSchemaAsync(schema);

            QueryResult <ContentItem> contentItems = await contentStore.Query(schema, queryParameters);

            foreach (ContentItem contentItem in contentItems.Items)
            {
                contentItem.ApplySchema(schemaModel);
            }

            QueryResult <RestContentItem> resultQuery = new QueryResult <RestContentItem>()
            {
                Offset     = contentItems.Offset,
                Count      = contentItems.Count,
                TotalCount = contentItems.TotalCount,
                Items      = contentItems.Items.Select(x => x.ToRest()).ToList()
            };

            string json = jsonService.Serialize(resultQuery);

            await context.Response.WriteAsync(json);
        }
        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);
        }
        public async Task InvokeAsync(
            HttpContext context,
            ISchemaStorage schemaStorage,
            JsonService jsonService)
        {
            QueryResult <ContentSchema> items = schemaStorage
                                                .QueryContentSchemas();

            QueryResult <RestContentSchema> restQueryResult = new QueryResult <RestContentSchema>();

            restQueryResult.Items      = items.Items.Select(x => x.ToRest()).ToList();
            restQueryResult.Offset     = items.Offset;
            restQueryResult.Count      = items.Count;
            restQueryResult.TotalCount = items.TotalCount;

            string json = jsonService.Serialize(restQueryResult);

            await context.Response.WriteAsync(json);
        }
        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);
        }
예제 #7
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);
        }