11using System ;
22using System . Collections . Generic ;
3+ using System . Linq ;
34using Newtonsoft . Json ;
45using Newtonsoft . Json . Linq ;
56using Our . Umbraco . DocTypeGridEditor . Models ;
@@ -31,15 +32,16 @@ public static IPublishedContent ConvertValueToContent(string id, string docTypeA
3132 if ( Guid . TryParse ( docTypeAlias , out docTypeGuid ) )
3233 docTypeAlias = Services . ContentTypeService . GetAliasByGuid ( docTypeGuid ) ;
3334
34- var contentType = PublishedContentType . Get ( PublishedItemType . Content , docTypeAlias ) ;
35- var properties = new List < IPublishedProperty > ( ) ;
35+ var publishedContentType = PublishedContentType . Get ( PublishedItemType . Content , docTypeAlias ) ;
36+ var contentType = ApplicationContext . Current . Services . ContentTypeService . GetContentType ( docTypeAlias ) ;
37+ var properties = new List < IPublishedProperty > ( ) ;
3638
3739 // Convert all the properties
3840 var data = JsonConvert . DeserializeObject ( dataJson ) ;
3941 var propValues = ( ( JObject ) data ) . ToObject < Dictionary < string , object > > ( ) ;
4042 foreach ( var jProp in propValues )
4143 {
42- var propType = contentType . GetPropertyType ( jProp . Key ) ;
44+ var propType = publishedContentType . GetPropertyType ( jProp . Key ) ;
4345 if ( propType != null )
4446 {
4547 /* Because we never store the value in the database, we never run the property editors
@@ -58,7 +60,14 @@ public static IPublishedContent ConvertValueToContent(string id, string docTypeA
5860
5961 var newValue = propEditor . ValueEditor . ConvertEditorToDb ( contentPropData , jProp . Value ) ;
6062
61- properties . Add ( new DetachedPublishedProperty ( propType , newValue ) ) ;
63+ /* Now that we have the DB stored value, we actually need to then convert it into it's
64+ * XML serialized state as expected by the published property by calling ConvertDbToString
65+ */
66+ var propType2 = contentType . PropertyTypes . Single ( x => x . Alias == propType . PropertyTypeAlias ) ;
67+ var newValue2 = propEditor . ValueEditor . ConvertDbToString ( new Property ( propType2 , newValue ) , propType2 ,
68+ ApplicationContext . Current . Services . DataTypeService ) ;
69+
70+ properties . Add ( new DetachedPublishedProperty ( propType , newValue2 ) ) ;
6271 }
6372 }
6473
@@ -69,7 +78,7 @@ public static IPublishedContent ConvertValueToContent(string id, string docTypeA
6978 // Do nothing, we just want to parse out the name if we can
7079 }
7180
72- return new DetachedPublishedContent ( nameObj == null ? null : nameObj . ToString ( ) , contentType ,
81+ return new DetachedPublishedContent ( nameObj == null ? null : nameObj . ToString ( ) , publishedContentType ,
7382 properties . ToArray ( ) ) ;
7483 }
7584 } ) ;
0 commit comments