Example #1
0
        public virtual void Patch(PropertyEntity target)
        {
            target.PropertyValueType = PropertyValueType;
            target.IsEnum            = IsEnum;
            target.IsMultiValue      = IsMultiValue;
            target.IsLocaleDependant = IsLocaleDependant;
            target.IsRequired        = IsRequired;
            target.TargetType        = TargetType;
            target.Name = Name;

            if (!PropertyAttributes.IsNullCollection())
            {
                var attributeComparer = AnonymousComparer.Create((PropertyAttributeEntity x) => x.IsTransient() ? x.PropertyAttributeName : x.Id);
                PropertyAttributes.Patch(target.PropertyAttributes, attributeComparer, (sourceAsset, targetAsset) => sourceAsset.Patch(targetAsset));
            }
            if (!DictionaryValues.IsNullCollection())
            {
                DictionaryValues.Patch(target.DictionaryValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
            }
            if (!DisplayNames.IsNullCollection())
            {
                var displayNamesComparer = AnonymousComparer.Create((PropertyDisplayNameEntity x) => $"{x.Name}-{x.Locale}");
                DisplayNames.Patch(target.DisplayNames, displayNamesComparer, (sourceDisplayName, targetDisplayName) => sourceDisplayName.Patch(targetDisplayName));
            }

            if (!ValidationRules.IsNullCollection())
            {
                ValidationRules.Patch(target.ValidationRules, (sourceRule, targetRule) => sourceRule.Patch(targetRule));
            }
        }
Example #2
0
        public virtual object Clone()
        {
            var result = MemberwiseClone() as Property;

            if (Attributes != null)
            {
                result.Attributes = Attributes.Select(x => x.Clone()).OfType <PropertyAttribute>().ToList();
            }
            if (DictionaryValues != null)
            {
                result.DictionaryValues = DictionaryValues.Select(x => x.Clone()).OfType <PropertyDictionaryValue>().ToList();
            }
            if (DisplayNames != null)
            {
                result.DisplayNames = DisplayNames.Select(x => x.Clone()).OfType <PropertyDisplayName>().ToList();
            }
            if (ValidationRules != null)
            {
                result.ValidationRules = ValidationRules.Select(x => x.Clone()).OfType <PropertyValidationRule>().ToList();
            }
            if (Values != null)
            {
                result.Values = Values.Select(x => x.Clone()).OfType <PropertyValue>().ToList();
            }
            return(result);
        }
Example #3
0
 public bool IsPropertyThatIsNotNull(ISymbol property)
 {
     if (DictionaryValues != null && DictionaryValues.Equals(property.OriginalDefinition))
     {
         return(true);
     }
     if (DictionaryValues != null && DictionaryKeys.Equals(property.OriginalDefinition))
     {
         return(true);
     }
     if (ExternalNotNullMethods.Contains(property))
     {
         return(true);
     }
     return(false);
 }
Example #4
0
        public virtual void ActualizeValues()
        {
            var dictLocalizedValues = new List <PropertyValue>();

            if (Values != null)
            {
                foreach (var propValue in Values)
                {
                    if (Dictionary && DictionaryValues != null)
                    {
                        /// Actualize  dictionary property value from property meta-information instead stored
                        if (propValue.ValueId != null)
                        {
                            var dictValue = DictionaryValues.FirstOrDefault(x => x.Id == propValue.ValueId);
                            if (dictValue != null)
                            {
                                propValue.Value = dictValue.Value;
                            }
                        }
                        if (Multilanguage)
                        {
                            foreach (var dictValue in DictionaryValues.Where(x => x.Alias.EqualsInvariant(propValue.Alias)))
                            {
                                var langDictPropValue = propValue.Clone() as PropertyValue;
                                langDictPropValue.Id           = null;
                                langDictPropValue.LanguageCode = dictValue.LanguageCode;
                                langDictPropValue.Value        = dictValue.Value;
                                dictLocalizedValues.Add(langDictPropValue);
                            }
                        }
                    }
                }
                foreach (var localizedDictValue in dictLocalizedValues)
                {
                    if (!Values.Any(x => x.Alias.EqualsInvariant(localizedDictValue.Alias) && x.LanguageCode.EqualsInvariant(localizedDictValue.LanguageCode)))
                    {
                        Values.Add(localizedDictValue);
                    }
                }
            }
        }
Example #5
0
        public virtual Property ToModel(Property property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            property.Id           = Id;
            property.CreatedBy    = CreatedBy;
            property.CreatedDate  = CreatedDate;
            property.ModifiedBy   = ModifiedBy;
            property.ModifiedDate = ModifiedDate;

            property.CatalogId  = CatalogId;
            property.CategoryId = CategoryId;


            property.Name          = Name;
            property.Required      = IsRequired;
            property.Multivalue    = IsMultiValue;
            property.Multilanguage = IsLocaleDependant;
            property.Dictionary    = IsEnum;
            property.ValueType     = (PropertyValueType)PropertyValueType;
            property.Type          = EnumUtility.SafeParse(TargetType, PropertyType.Catalog);

            property.DictionaryValues = DictionaryValues.Select(x => x.ToModel(AbstractTypeFactory <PropertyDictionaryValue> .TryCreateInstance())).ToList();
            property.Attributes       = PropertyAttributes.Select(x => x.ToModel(AbstractTypeFactory <PropertyAttribute> .TryCreateInstance())).ToList();
            property.DisplayNames     = DisplayNames.Select(x => x.ToModel(AbstractTypeFactory <PropertyDisplayName> .TryCreateInstance())).ToList();
            property.ValidationRules  = ValidationRules.Select(x => x.ToModel(AbstractTypeFactory <PropertyValidationRule> .TryCreateInstance())).ToList();
            foreach (var rule in property.ValidationRules)
            {
                rule.Property = property;
            }

            return(property);
        }