public ContentResponseMessage SaveContent([FromBody] SaveContentRequestBody data) { if (!ModelState.IsValid) { return(ContentResponseMessage.CreateFrom(ModelState)); } var contentType = ContentTypeProvider.Get(data.ContentTypeId); var b = (IContent)JsonConvert.DeserializeObject(data.Content, contentType.Type, PolymorphicFormConverter); if (b.Id != null) { var a = (IContent)typeof(IContainerSpecificContentGetter).GetMethod(nameof(ContainerSpecificContentGetter.Get)).MakeGenericMethod(contentType.Type).Invoke(ContainerSpecificContentGetter, new[] { data.Id, null, contentType.Container }); foreach (var coreInterface in ContentTypeCoreInterfaceProvider.GetFor(contentType.Id)) { foreach (var propertyDefinition in coreInterface.PropertyDefinitions) { var display = propertyDefinition.Attributes.OfType <DisplayAttribute>().FirstOrDefault(); if (display != null && display.GetAutoGenerateField() == false) { continue; } propertyDefinition.Setter(a, propertyDefinition.Getter(b)); } } foreach (var propertyDefinition in PropertyDefinitionProvider.GetFor(contentType.Id)) { var display = propertyDefinition.Attributes.OfType <DisplayAttribute>().FirstOrDefault(); if (display != null && display.GetAutoGenerateField() == false) { continue; } propertyDefinition.Setter(a, propertyDefinition.Getter(b)); } ContainerSpecificContentUpdater.Update(a, contentType.Container); return(new ContentResponseMessage(true, "Updated")); } else { ContainerSpecificContentCreator.Create(b, contentType.Container); return(new ContentResponseMessage(true, "Created")); } }
public Document Serialize(IContent content, ContentTypeDescriptor contentType) { var globalInterfaces = new List <DocumentInterface>(); foreach (var coreInterface in ContentTypeCoreInterfaceProvider.GetFor(contentType.Id)) { globalInterfaces.Add(DocumentInterface.CreateFrom(coreInterface.Id, GetProperties(content, coreInterface.PropertyDefinitions))); } var global = DocumentFacet.CreateFrom(DocumentLanguageConstants.Global, globalInterfaces, GetProperties(content, PropertyDefinitionProvider.GetFor(contentType.Id))); return(Document.CreateFrom(content.Id, global, Enumerable.Empty <DocumentFacet>().ToDictionary(f => f.Language, f => f))); }
public IContent Deserialize(Document document, ContentTypeDescriptor contentType, string language) { var content = ContentInstanceCreator.Create(contentType); foreach (var coreInterface in ContentTypeCoreInterfaceProvider.GetFor(contentType.Id)) { if (document.GlobalFacet.Interfaces.TryGetValue(coreInterface.Id, out var languageIndependentInterface)) { SetProperties(content, coreInterface.PropertyDefinitions, languageIndependentInterface.Properties); } } SetProperties(content, PropertyDefinitionProvider.GetFor(contentType.Id), document.GlobalFacet.Properties); return(content); }
public async Task <ContentResponseMessage> SaveContent([FromBody] SaveContentRequestBody data) { if (!ModelState.IsValid) { return(ContentResponseMessage.CreateFrom(ModelState)); } var contentType = ContentTypeProvider.Get(data.ContentTypeId); var b = JsonConvert.DeserializeObject(data.Content, contentType.Type, PolymorphicFormConverter); if (!TryValidateModel(b)) { return(ContentResponseMessage.CreateFrom(ModelState)); } if (PrimaryKeyGetter.Get(b).All(id => id != null)) { var a = await ContentGetter.GetAsync(contentType.Id, PrimaryKeyConverter.Convert(data.KeyValues, contentType.Id)).ConfigureAwait(false); foreach (var coreInterface in ContentTypeCoreInterfaceProvider.GetFor(contentType.Id)) { foreach (var propertyDefinition in coreInterface.PropertyDefinitions) { var display = propertyDefinition.Attributes.OfType <DisplayAttribute>().FirstOrDefault(); if (display != null && display.GetAutoGenerateField() == false) { continue; } propertyDefinition.Setter(a, propertyDefinition.Getter(b)); } } foreach (var propertyDefinition in PropertyDefinitionProvider.GetFor(contentType.Id)) { var display = propertyDefinition.Attributes.OfType <DisplayAttribute>().FirstOrDefault(); if (display != null && display.GetAutoGenerateField() == false) { continue; } propertyDefinition.Setter(a, propertyDefinition.Getter(b)); } if (!TryValidateModel(b)) { throw new Exception("a was valid but b was not."); } await ContentUpdater.UpdateAsync(a).ConfigureAwait(false); return(new ContentResponseMessage(true, "Updated")); } else { await ContentCreator.CreateAsync(b).ConfigureAwait(false); return(new ContentResponseMessage(true, "Created")); } }