public virtual DynamicPropertyObjectValue ToModel(DynamicPropertyObjectValue propValue) { if (propValue == null) { throw new ArgumentNullException(nameof(propValue)); } propValue.Locale = Locale; propValue.ObjectId = ObjectId; propValue.ObjectType = ObjectType; propValue.ValueType = EnumUtility.SafeParse(ValueType, DynamicPropertyValueType.LongText); propValue.PropertyId = PropertyId; propValue.PropertyName = PropertyName; if (!string.IsNullOrEmpty(DictionaryItemId)) { propValue.ValueId = DictionaryItemId; propValue.Value = ShortTextValue; } else { propValue.Value = GetValue(propValue.ValueType); } return(propValue); }
public virtual DynamicPropertyObjectValueEntity FromModel(DynamicPropertyObjectValue propValue) { if (propValue == null) { throw new ArgumentNullException(nameof(propValue)); } Locale = propValue.Locale; ObjectId = propValue.ObjectId; ObjectType = propValue.ObjectType; ValueType = propValue.ValueType.ToString(); DictionaryItemId = propValue.ValueId; var dictItem = propValue.Value as DynamicPropertyDictionaryItem; if (dictItem == null) { if (propValue.Value is JObject jObject) { dictItem = jObject.ToObject <DynamicPropertyDictionaryItem>(); } } if (dictItem != null) { DictionaryItemId = dictItem.Id; } else { SetValue(propValue.ValueType, propValue.Value); } return(this); }
public static DynamicPropertyObjectValue ToModel(this DynamicPropertyObjectValueEntity entity) { var retVal = new DynamicPropertyObjectValue(); retVal.Locale = entity.Locale; if (entity.DictionaryItem != null) { retVal.Value = entity.DictionaryItem.ToModel(); } else { retVal.Value = entity.RawValue(); } return(retVal); }
public virtual DynamicPropertyObjectValueEntity FromModel(DynamicPropertyObjectValue propValue) { if (propValue == null) { throw new ArgumentNullException(nameof(propValue)); } Locale = propValue.Locale; ObjectId = propValue.ObjectId; ObjectType = propValue.ObjectType; ValueType = propValue.ValueType.ToString(); DictionaryItemId = propValue.ValueId; SetValue(propValue.ValueType, propValue.Value); return(this); }
public virtual DynamicPropertyObjectValue ToModel(DynamicPropertyObjectValue propValue) { if (propValue == null) { throw new ArgumentNullException(nameof(propValue)); } propValue.Locale = Locale; propValue.ObjectId = ObjectId; propValue.ObjectType = ObjectType; propValue.ValueType = EnumUtility.SafeParse(ValueType, DynamicPropertyValueType.LongText); if (DictionaryItem != null) { propValue.Value = DictionaryItem.ToModel(AbstractTypeFactory <DynamicPropertyDictionaryItem> .TryCreateInstance()); } else { propValue.Value = GetValue(propValue.ValueType); } return(propValue); }
public virtual DynamicPropertyObjectValueEntity FromModel(DynamicPropertyObjectValue propValue, IHasDynamicProperties owner, DynamicProperty dynamicProperty) { if (propValue == null) { throw new ArgumentNullException(nameof(propValue)); } Locale = propValue.Locale; ObjectId = propValue.ObjectId ?? owner.Id; ObjectType = propValue.ObjectType ?? owner.ObjectType ?? owner.GetType().FullName; var dynamicPropertyValueType = propValue.ValueType == DynamicPropertyValueType.Undefined ? dynamicProperty.ValueType : propValue.ValueType; ValueType = dynamicPropertyValueType.ToString(); PropertyId = propValue.PropertyId ?? dynamicProperty.Id; PropertyName = propValue.PropertyName ?? dynamicProperty.Name; DictionaryItemId = propValue.ValueId; var dictItem = propValue.Value as DynamicPropertyDictionaryItem; if (dictItem == null && propValue.Value is JObject jObject) { dictItem = jObject.ToObject <DynamicPropertyDictionaryItem>(); } if (dictItem != null) { DictionaryItemId = dictItem.Id; PropertyId = dictItem.PropertyId; ShortTextValue = dictItem.Name; } else { SetValue(dynamicPropertyValueType, propValue.Value); } return(this); }
public static DynamicPropertyObjectValueEntity ToEntity(this DynamicPropertyObjectValue propertyValue, DynamicObjectProperty property, string objectId) { var result = new DynamicPropertyObjectValueEntity { ObjectType = property.ObjectType, ObjectId = property.ObjectId, ValueType = property.ValueType.ToString() }; result.InjectFrom(propertyValue); if (!string.IsNullOrEmpty(objectId)) { result.ObjectId = objectId; } if (property.IsDictionary) { var item = propertyValue.Value as DynamicPropertyDictionaryItem; if (item == null) { var jObject = propertyValue.Value as JObject; if (jObject != null) { item = jObject.ToObject <DynamicPropertyDictionaryItem>(); } } if (item != null) { result.DictionaryItemId = item.Id; } } else { switch (property.ValueType) { case DynamicPropertyValueType.Boolean: result.BooleanValue = propertyValue.Value.ToNullable <Boolean>(); break; case DynamicPropertyValueType.DateTime: result.DateTimeValue = propertyValue.Value.ToNullable <DateTime>(); break; case DynamicPropertyValueType.Decimal: result.DecimalValue = propertyValue.Value.ToNullable <Decimal>(); break; case DynamicPropertyValueType.Integer: result.IntegerValue = propertyValue.Value.ToNullable <Int32>(); break; case DynamicPropertyValueType.ShortText: result.ShortTextValue = (string)propertyValue.Value; break; default: result.LongTextValue = (string)propertyValue.Value; break; } } return(result); }
public static DynamicPropertyObjectValueEntity ToEntity(this DynamicPropertyObjectValue propertyValue, DynamicObjectProperty property) { var result = new DynamicPropertyObjectValueEntity { ObjectType = property.ObjectType, ObjectId = property.ObjectId, ValueType = property.ValueType.ToString() }; result.InjectFrom(propertyValue); if (property.IsDictionary) { var item = propertyValue.Value as DynamicPropertyDictionaryItem; if (item == null) { var jObject = propertyValue.Value as JObject; if (jObject != null) { item = jObject.ToObject <DynamicPropertyDictionaryItem>(); } } if (item != null) { result.DictionaryItemId = item.Id; } } else { switch (property.ValueType) { case DynamicPropertyValueType.Boolean: result.BooleanValue = Convert.ToBoolean(propertyValue.Value); break; case DynamicPropertyValueType.DateTime: result.DateTimeValue = Convert.ToDateTime(propertyValue.Value, CultureInfo.InvariantCulture); break; case DynamicPropertyValueType.Decimal: result.DecimalValue = Convert.ToDecimal(propertyValue.Value, CultureInfo.InvariantCulture); break; case DynamicPropertyValueType.Integer: result.IntegerValue = Convert.ToInt32(propertyValue.Value, CultureInfo.InvariantCulture); break; case DynamicPropertyValueType.LongText: case DynamicPropertyValueType.Html: result.LongTextValue = (string)propertyValue.Value; break; default: result.ShortTextValue = (string)propertyValue.Value; break; } } return(result); }