public static void Patch(this DynamicPropertyObjectValueEntity source, DynamicPropertyObjectValueEntity target) { if (target == null) { throw new ArgumentNullException("target"); } var patchInjectionPolicy = new PatchInjection <DynamicPropertyObjectValueEntity>(x => x.Locale, x => x.LongTextValue, x => x.BooleanValue, x => x.DateTimeValue, x => x.DecimalValue, x => x.DictionaryItemId, x => x.IntegerValue, x => x.ShortTextValue); target.InjectFrom(patchInjectionPolicy, source); }
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); }