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 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); }
public static ContentSchema ToModel(this RestContentSchema restContentItem) { ContentSchema contentSchema = new ContentSchema(restContentItem.Name); contentSchema.Id = restContentItem.Id; contentSchema.CreatedAt = restContentItem.CreatedAt; contentSchema.ModifiedAt = restContentItem.ModifiedAt; contentSchema.Version = restContentItem.Version; contentSchema.ListFields = restContentItem.ListFields.ToList(); contentSchema.ReferenceFields = restContentItem.ReferenceFields.ToList(); contentSchema.OrderFields = restContentItem.OrderFields.ToList(); foreach (var mongoField in restContentItem.Fields) { contentSchema.Fields.Add(mongoField.Key, mongoField.Value.ToModel()); } return(contentSchema); }
public static RestContentSchema ToRest(this ContentSchema contentSchema) { RestContentSchema restContentItem = new RestContentSchema(); restContentItem.Id = contentSchema.Id; restContentItem.Name = contentSchema.Name; restContentItem.CreatedAt = contentSchema.CreatedAt; restContentItem.ModifiedAt = contentSchema.ModifiedAt; restContentItem.Version = contentSchema.Version; restContentItem.ListFields = contentSchema.ListFields.ToList(); restContentItem.ReferenceFields = contentSchema.ReferenceFields.ToList(); restContentItem.OrderFields = contentSchema.OrderFields.ToList(); foreach (var field in contentSchema.Fields) { restContentItem.Fields.Add(field.Key, field.Value.ToRest()); } return(restContentItem); }
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); }