public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            try
            {
                if (source != null && !source.ToString().IsNullOrWhiteSpace() && source.ToString() != "{}")
                {
                    var value = JsonConvert.DeserializeObject <PhotonValue>(source.ToString());

                    if (value.Tags != null && value.Tags.Count > 0)
                    {
                        // Get the meta data doc type
                        var metaDataDocTypeAlias = PhotonHelper.GetMetaDataDocType(propertyType.DataTypeId);
                        var metaDataDocType      = PublishedContentType.Get(PublishedItemType.Content, metaDataDocTypeAlias);

                        // Loop tags and covert meta data
                        foreach (var tag in value.Tags)
                        {
                            tag.MetaData = ConvertDataToSource_DocType(propertyType, metaDataDocType, tag.RawMetaData, preview);
                        }
                    }

                    return(value);
                }
            }
            catch (Exception e)
            {
                LogHelper.Error <PhotonValueConverter>("Error converting value", e);
            }

            return(null);
        }
            public override object ConvertEditorToDb(ContentPropertyData editorValue,
                                                     object currentValue)
            {
                var oldValue = new PhotonValue();
                var newValue = new PhotonValue();

                // Get the old src path
                if (currentValue != null && !string.IsNullOrEmpty(currentValue.ToString()))
                {
                    oldValue = PhotonValue.Parse(currentValue.ToString());
                }

                //get the new src path
                if (editorValue.Value != null)
                {
                    newValue = PhotonValue.Parse(editorValue.Value.ToString());
                }

                //handle storing / deleteing the media items
                ConvertDbToEditor_HandleMedia(editorValue, oldValue, newValue);

                // Loop tags and covert meta data
                if (newValue != null && newValue.Tags != null && newValue.Tags.Count > 0)
                {
                    // Get the meta data doc type
                    var metaDataDocTypeAlias = PhotonHelper.GetMetaDataDocType(editorValue.PreValues);
                    var metaDataDocType      = ApplicationContext.Current.Services.ContentTypeService.GetContentType(metaDataDocTypeAlias);

                    foreach (var tag in newValue.Tags)
                    {
                        tag.RawMetaData = ConvertEditorToDb_DocType(metaDataDocType, tag.RawMetaData);
                    }
                }

                // Return json
                return(JsonConvert.SerializeObject(newValue));
            }
            public override object ConvertDbToEditor(Property property, PropertyType propertyType,
                                                     IDataTypeService dataTypeService)
            {
                // Make sure we have a value
                if (property.Value == null || string.IsNullOrWhiteSpace(property.Value.ToString()))
                {
                    return(string.Empty);
                }

                // Parse to photon value for ease
                var value = JsonConvert.DeserializeObject <PhotonValue>(property.Value.ToString());

                if (value == null)
                {
                    return(string.Empty);
                }

                // Loop tags and covert meta data
                if (value.Tags != null && value.Tags.Count > 0)
                {
                    // Get the meta data doc type
                    var metaDataDocTypeAlias = PhotonHelper.GetMetaDataDocType(propertyType.DataTypeDefinitionId);
                    var metaDataDocType      = ApplicationContext.Current.Services.ContentTypeService.GetContentType(metaDataDocTypeAlias);

                    foreach (var tag in value.Tags)
                    {
                        tag.RawMetaData = ConvertDbToEditor_DocType(metaDataDocType, tag.RawMetaData);
                    }
                }

                // We serialize back down as we want the editor to handle
                // the data as a generic object type, not our specific classes
                property.Value = JsonConvert.SerializeObject(value);

                return(base.ConvertDbToEditor(property, propertyType, dataTypeService));
            }
            public override string ConvertDbToString(Property property, PropertyType propertyType,
                                                     IDataTypeService dataTypeService)
            {
                // Make sure we have a value
                if (property.Value == null || string.IsNullOrWhiteSpace(property.Value.ToString()))
                {
                    return(string.Empty);
                }

                // Parse to photon value for ease
                var value = JsonConvert.DeserializeObject <PhotonValue>(property.Value.ToString());

                if (value == null)
                {
                    return(string.Empty);
                }

                // Loop tags and covert meta data
                if (value.Tags != null && value.Tags.Count > 0)
                {
                    // Get the meta data doc type
                    var metaDataDocTypeAlias = PhotonHelper.GetMetaDataDocType(propertyType.DataTypeDefinitionId);
                    var metaDataDocType      = ApplicationContext.Current.Services.ContentTypeService.GetContentType(metaDataDocTypeAlias);

                    foreach (var tag in value.Tags)
                    {
                        tag.RawMetaData = ConvertDbToString_DocType(metaDataDocType, tag.RawMetaData);
                    }
                }

                // Update the value on the property
                property.Value = JsonConvert.SerializeObject(value);

                // Pass the call down
                return(base.ConvertDbToString(property, propertyType, dataTypeService));
            }