示例#1
0
        public virtual Catalog ToModel(Catalog catalog)
        {
            if (catalog == null)
            {
                throw new ArgumentNullException(nameof(catalog));
            }

            catalog.Id        = Id;
            catalog.Name      = Name;
            catalog.IsVirtual = Virtual;

            catalog.Languages = new List <CatalogLanguage>();
            var defaultLanguage = (new CatalogLanguageEntity {
                Language = string.IsNullOrEmpty(DefaultLanguage) ? "en-us" : DefaultLanguage
            }).ToModel(AbstractTypeFactory <CatalogLanguage> .TryCreateInstance());

            defaultLanguage.IsDefault = true;
            catalog.Languages.Add(defaultLanguage);
            //populate additional languages
            foreach (var additionalLanguage in CatalogLanguages.Where(x => x.Language != defaultLanguage.LanguageCode).Select(x => x.ToModel(AbstractTypeFactory <CatalogLanguage> .TryCreateInstance())))
            {
                catalog.Languages.Add(additionalLanguage);
            }

            //item property values
            catalog.PropertyValues = CatalogPropertyValues.OrderBy(x => x.Name).SelectMany(x => x.ToModel(AbstractTypeFactory <PropertyValue> .TryCreateInstance())).ToList();

            //Self properties
            catalog.Properties = Properties.Where(x => x.CategoryId == null)
                                 .OrderBy(x => x.Name)
                                 .Select(x => x.ToModel(AbstractTypeFactory <Property> .TryCreateInstance())).ToList();

            return(catalog);
        }
示例#2
0
        public virtual Catalog ToModel(Catalog catalog)
        {
            if (catalog == null)
            {
                throw new ArgumentNullException(nameof(catalog));
            }

            catalog.Id        = Id;
            catalog.Name      = Name;
            catalog.IsVirtual = Virtual;

            catalog.Languages = new List <CatalogLanguage>();
            var defaultLanguage = (new CatalogLanguageEntity {
                Language = string.IsNullOrEmpty(DefaultLanguage) ? "en-us" : DefaultLanguage
            }).ToModel(AbstractTypeFactory <CatalogLanguage> .TryCreateInstance());

            defaultLanguage.IsDefault = true;
            catalog.Languages.Add(defaultLanguage);
            //populate additional languages
            foreach (var additionalLanguage in CatalogLanguages.Where(x => x.Language != defaultLanguage.LanguageCode).Select(x => x.ToModel(AbstractTypeFactory <CatalogLanguage> .TryCreateInstance())))
            {
                catalog.Languages.Add(additionalLanguage);
            }

            //Self properties
            catalog.Properties = Properties.Where(x => x.CategoryId == null)
                                 .OrderBy(x => x.Name)
                                 .Select(x => x.ToModel(AbstractTypeFactory <Property> .TryCreateInstance())).ToList();
            foreach (var propValueEntities in CatalogPropertyValues.GroupBy(x => x.Name))
            {
                var propValues = propValueEntities.OrderBy(x => x.Id).Select(x => x.ToModel(AbstractTypeFactory <PropertyValue> .TryCreateInstance())).ToList();
                var property   = catalog.Properties.Where(x => x.Type == PropertyType.Category)
                                 .FirstOrDefault(x => x.IsSuitableForValue(propValues.First()));
                if (property == null)
                {
                    //Need add transient  property (without meta information) for each values group with the same property name
                    property = AbstractTypeFactory <Property> .TryCreateInstance();

                    property.Name = propValueEntities.Key;
                    property.Type = PropertyType.Catalog;
                    catalog.Properties.Add(property);
                }
                property.Values = propValues;
            }

            return(catalog);
        }
示例#3
0
        public virtual void Patch(CatalogEntity target)
        {
            target.Name            = Name;
            target.DefaultLanguage = DefaultLanguage;

            //Languages patch
            if (!CatalogLanguages.IsNullCollection())
            {
                var languageComparer = AnonymousComparer.Create((CatalogLanguageEntity x) => x.Language);
                CatalogLanguages.Patch(target.CatalogLanguages, languageComparer,
                                       (sourceLang, targetlang) => sourceLang.Patch(targetlang));
            }

            //Property values
            if (!CatalogPropertyValues.IsNullCollection())
            {
                CatalogPropertyValues.Patch(target.CatalogPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
            }
        }
        public virtual Catalog ToModel(Catalog catalog)
        {
            if (catalog == null)
            {
                throw new ArgumentNullException(nameof(catalog));
            }

            catalog.Id        = Id;
            catalog.Name      = Name;
            catalog.IsVirtual = Virtual;
            catalog.OuterId   = OuterId;

            catalog.Languages = new List <CatalogLanguage>();
            var defaultLanguage = (new CatalogLanguageEntity {
                Language = string.IsNullOrEmpty(DefaultLanguage) ? "en-us" : DefaultLanguage
            }).ToModel(AbstractTypeFactory <CatalogLanguage> .TryCreateInstance());

            defaultLanguage.IsDefault = true;
            catalog.Languages.Add(defaultLanguage);
            //populate additional languages
            foreach (var additionalLanguage in CatalogLanguages.Where(x => x.Language != defaultLanguage.LanguageCode).Select(x => x.ToModel(AbstractTypeFactory <CatalogLanguage> .TryCreateInstance())))
            {
                catalog.Languages.Add(additionalLanguage);
            }

            //Self properties
            catalog.Properties = Properties.Where(x => x.CategoryId == null)
                                 .OrderBy(x => x.Name)
                                 .Select(x => x.ToModel(AbstractTypeFactory <Property> .TryCreateInstance())).ToList();


            foreach (var property in catalog.Properties)
            {
                property.IsReadOnly = property.Type != PropertyType.Catalog;
                property.Values     = CatalogPropertyValues.Where(pr => pr.Name.EqualsInvariant(property.Name)).OrderBy(x => x.DictionaryItem?.SortOrder)
                                      .ThenBy(x => x.Name)
                                      .SelectMany(x => x.ToModel(AbstractTypeFactory <PropertyValue> .TryCreateInstance())).ToList();
            }

            return(catalog);
        }