/// <summary> /// Patch changes /// </summary> /// <param name="source"></param> /// <param name="target"></param> public static void Patch(this dataModel.Property source, dataModel.Property target) { if (target == null) { throw new ArgumentNullException("target"); } var patchInjectionPolicy = new PatchInjection <dataModel.Property>(x => x.PropertyValueType, x => x.IsEnum, x => x.IsMultiValue, x => x.IsLocaleDependant, x => x.IsRequired, x => x.TargetType, x => x.Name); target.InjectFrom(patchInjectionPolicy, source); //Attributes patch if (!source.PropertyAttributes.IsNullCollection()) { var attributeComparer = AnonymousComparer.Create((dataModel.PropertyAttribute x) => x.IsTransient() ? x.PropertyAttributeName : x.Id); source.PropertyAttributes.Patch(target.PropertyAttributes, attributeComparer, (sourceAsset, targetAsset) => sourceAsset.Patch(targetAsset)); } //Property dict values if (!source.DictionaryValues.IsNullCollection()) { source.DictionaryValues.Patch(target.DictionaryValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue)); } }
/// <summary> /// Converting to foundation type /// </summary> /// <param name="catalog"></param> /// <returns></returns> public static dataModel.Property ToDataModel(this coreModel.Property property) { if (property == null) { throw new ArgumentNullException("property"); } var retVal = new dataModel.Property(); retVal.InjectFrom(property); retVal.PropertyValueType = (int)property.ValueType; retVal.IsMultiValue = property.Multivalue; retVal.IsLocaleDependant = property.Multilanguage; retVal.IsEnum = property.Dictionary; retVal.IsRequired = property.Required; retVal.TargetType = property.Type.ToString(); if (property.Attributes != null) { retVal.PropertyAttributes = new ObservableCollection <dataModel.PropertyAttribute>(); foreach (var attribute in property.Attributes) { var dbAttribute = attribute.ToDataModel(); retVal.PropertyAttributes.Add(dbAttribute); } } if (property.DictionaryValues != null) { retVal.DictionaryValues = new ObservableCollection <dataModel.PropertyDictionaryValue>(); foreach (var dictValue in property.DictionaryValues) { var dbDictValue = dictValue.ToDataModel(); retVal.DictionaryValues.Add(dbDictValue); } } if (property.DisplayNames != null) { foreach (var displayName in property.DisplayNames.Where(x => !String.IsNullOrEmpty(x.Name))) { var attributeName = "DisplayName" + displayName.LanguageCode; var existAttribute = retVal.PropertyAttributes.FirstOrDefault(x => x.PropertyAttributeName == attributeName); if (existAttribute == null) { existAttribute = new dataModel.PropertyAttribute { PropertyId = property.Id, PropertyAttributeName = attributeName, }; retVal.PropertyAttributes.Add(existAttribute); } existAttribute.PropertyAttributeValue = displayName.Name; } } return(retVal); }
/// <summary> /// Converting to foundation type /// </summary> /// <param name="catalog"></param> /// <returns></returns> public static dataModel.Property ToDataModel(this coreModel.Property property) { if (property == null) throw new ArgumentNullException("property"); var retVal = new dataModel.Property(); retVal.InjectFrom(property); retVal.PropertyValueType = (int)property.ValueType; retVal.IsMultiValue = property.Multivalue; retVal.IsLocaleDependant = property.Multilanguage; retVal.IsEnum = property.Dictionary; retVal.IsRequired = property.Required; retVal.TargetType = property.Type.ToString(); if (property.Attributes != null) { retVal.PropertyAttributes = new ObservableCollection<dataModel.PropertyAttribute>(); foreach (var attribute in property.Attributes) { var dbAttribute = attribute.ToDataModel(); retVal.PropertyAttributes.Add(dbAttribute); } } if (property.DictionaryValues != null) { retVal.DictionaryValues = new ObservableCollection<dataModel.PropertyDictionaryValue>(); foreach (var dictValue in property.DictionaryValues) { var dbDictValue = dictValue.ToDataModel(); retVal.DictionaryValues.Add(dbDictValue); } } if (property.DisplayNames != null) { foreach (var displayName in property.DisplayNames.Where(x=> !String.IsNullOrEmpty(x.Name))) { var attributeName = "DisplayName" + displayName.LanguageCode; var existAttribute = retVal.PropertyAttributes.FirstOrDefault(x => x.PropertyAttributeName == attributeName); if(existAttribute == null) { existAttribute = new dataModel.PropertyAttribute { PropertyId = property.Id, PropertyAttributeName = attributeName, }; retVal.PropertyAttributes.Add(existAttribute); } existAttribute.PropertyAttributeValue = displayName.Name; } } return retVal; }