Ejemplo n.º 1
0
        public virtual void TryInheritFrom(IEntity parent)
        {
            if (parent is Property parentProperty)
            {
                IsInherited     = true;
                Id              = parentProperty.Id;
                CreatedBy       = parentProperty.CreatedBy;
                ModifiedBy      = parentProperty.ModifiedBy;
                CreatedDate     = parentProperty.CreatedDate;
                ModifiedDate    = parentProperty.ModifiedDate;
                Required        = parentProperty.Required;
                Dictionary      = parentProperty.Dictionary;
                Multivalue      = parentProperty.Multivalue;
                Multilanguage   = parentProperty.Multilanguage;
                ValueType       = parentProperty.ValueType;
                Type            = parentProperty.Type;
                Attributes      = parentProperty.Attributes;
                DisplayNames    = parentProperty.DisplayNames;
                ValidationRules = parentProperty.ValidationRules;

                if (Values.IsNullOrEmpty() && !parentProperty.Values.IsNullOrEmpty())
                {
                    Values = new List <PropertyValue>();
                    foreach (var parentPropValue in parentProperty.Values)
                    {
                        var propValue = AbstractTypeFactory <PropertyValue> .TryCreateInstance();

                        propValue.TryInheritFrom(parentPropValue);
                        Values.Add(propValue);
                    }
                }
                foreach (var propValue in Values ?? Array.Empty <PropertyValue>())
                {
                    propValue.PropertyId = parentProperty.Id;
                    propValue.ValueType  = parentProperty.ValueType;
                }
            }

            if (parent is Catalog catalog)
            {
                var displayNamesComparer            = AnonymousComparer.Create((PropertyDisplayName x) => $"{x.LanguageCode}");
                var displayNamesForCatalogLanguages = catalog.Languages.Select(x => new PropertyDisplayName {
                    LanguageCode = x.LanguageCode
                }).ToList();
                //Leave display names only with catalog languages
                DisplayNames = DisplayNames.Intersect(displayNamesForCatalogLanguages, displayNamesComparer).ToList();
                //Add missed
                DisplayNames.AddRange(displayNamesForCatalogLanguages.Except(DisplayNames, displayNamesComparer));
                IsManageable = true;
            }
        }
Ejemplo n.º 2
0
        public virtual void TryInheritFrom(IEntity parent)
        {
            if (parent is Property parentProperty)
            {
                IsInherited     = true;
                Id              = parentProperty.Id ?? Id;
                Name            = parentProperty.Name ?? Name;
                CreatedBy       = parentProperty.CreatedBy ?? CreatedBy;
                ModifiedBy      = parentProperty.ModifiedBy ?? ModifiedBy;
                CreatedDate     = parentProperty.CreatedDate;
                ModifiedDate    = parentProperty.ModifiedDate ?? ModifiedDate;
                Required        = parentProperty.Required;
                Dictionary      = parentProperty.Dictionary;
                Multivalue      = parentProperty.Multivalue;
                Multilanguage   = parentProperty.Multilanguage;
                ValueType       = parentProperty.ValueType;
                Type            = parentProperty.Type;
                Attributes      = parentProperty.Attributes;
                DisplayNames    = parentProperty.DisplayNames;
                ValidationRules = parentProperty.ValidationRules;
                CatalogId       = parentProperty.CatalogId;
                CategoryId      = parentProperty.CategoryId;
                Hidden          = parentProperty.Hidden;

                foreach (var propValue in (Values ?? Array.Empty <PropertyValue>()).Where(x => x != null))
                {
                    propValue.PropertyId = parentProperty.Id;
                    propValue.ValueType  = parentProperty.ValueType;
                }
            }

            if (parent is Catalog catalog)
            {
                var displayNamesComparer            = AnonymousComparer.Create((PropertyDisplayName x) => $"{x.LanguageCode}");
                var displayNamesForCatalogLanguages = catalog.Languages.Select(x => new PropertyDisplayName {
                    LanguageCode = x.LanguageCode
                }).ToList();
                //Leave display names only with catalog languages
                DisplayNames = DisplayNames.Intersect(displayNamesForCatalogLanguages, displayNamesComparer).ToList();
                //Add missed
                DisplayNames.AddRange(displayNamesForCatalogLanguages.Except(DisplayNames, displayNamesComparer));
            }
        }