Пример #1
0
        public virtual void Patch(CategoryEntity target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            target.CatalogId        = CatalogId;
            target.ParentCategoryId = ParentCategoryId;
            target.Code             = Code;
            target.Name             = Name;
            target.TaxType          = TaxType;
            target.Priority         = Priority;
            target.IsActive         = IsActive;

            if (!CategoryPropertyValues.IsNullCollection())
            {
                CategoryPropertyValues.Patch(target.CategoryPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
            }

            if (!OutgoingLinks.IsNullCollection())
            {
                var categoryRelationComparer = AnonymousComparer.Create((CategoryRelationEntity x) => string.Join(":", x.TargetCatalogId, x.TargetCategoryId));
                OutgoingLinks.Patch(target.OutgoingLinks, categoryRelationComparer, (sourceLink, targetLink) => sourceLink.Patch(targetLink));
            }

            if (!Images.IsNullCollection())
            {
                Images.Patch(target.Images, (sourceImage, targetImage) => sourceImage.Patch(targetImage));
            }
        }
Пример #2
0
        public virtual void Patch(CategoryEntity target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            target.CatalogId        = CatalogId;
            target.ParentCategoryId = ParentCategoryId;
            target.Code             = Code;
            target.Name             = Name;
            target.TaxType          = TaxType;
            target.Priority         = Priority;
            target.IsActive         = IsActive;

            if (!CategoryPropertyValues.IsNullCollection())
            {
                CategoryPropertyValues.Patch(target.CategoryPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
            }

            if (!OutgoingLinks.IsNullCollection())
            {
                OutgoingLinks.Patch(target.OutgoingLinks, (sourceLink, targetLink) => sourceLink.Patch(targetLink));
            }

            if (!Images.IsNullCollection())
            {
                Images.Patch(target.Images, (sourceImage, targetImage) => sourceImage.Patch(targetImage));
            }
        }
Пример #3
0
        public virtual Category ToModel(Category category)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

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

            category.Code     = Code;
            category.Name     = Name;
            category.Priority = Priority;
            category.TaxType  = TaxType;

            category.CatalogId = CatalogId;

            category.ParentId = ParentCategoryId;
            category.IsActive = IsActive;

            category.Links      = OutgoingLinks.Select(x => x.ToModel(new CategoryLink())).ToList();
            category.Images     = Images.OrderBy(x => x.SortOrder).Select(x => x.ToModel(AbstractTypeFactory <Image> .TryCreateInstance())).ToList();
            category.Properties = Properties.Select(x => x.ToModel(AbstractTypeFactory <Property> .TryCreateInstance())).ToList();

            //category property values
            category.PropertyValues = CategoryPropertyValues
                                      .OrderBy(x => x.DictionaryItem?.SortOrder)
                                      .ThenBy(x => x.Name)
                                      .SelectMany(x => x.ToModel(AbstractTypeFactory <PropertyValue> .TryCreateInstance())).ToList();
            return(category);
        }
Пример #4
0
        public virtual Category ToModel(Category category)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

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

            category.Code     = Code;
            category.Name     = Name;
            category.Priority = Priority;
            category.TaxType  = TaxType;

            category.CatalogId = CatalogId;

            category.ParentId = ParentCategoryId;
            category.IsActive = IsActive;

            category.Links      = OutgoingLinks.Select(x => x.ToModel(new CategoryLink())).ToList();
            category.Images     = Images.OrderBy(x => x.SortOrder).Select(x => x.ToModel(AbstractTypeFactory <Image> .TryCreateInstance())).ToList();
            category.Properties = Properties.Select(x => x.ToModel(AbstractTypeFactory <Property> .TryCreateInstance())).ToList();
            foreach (var propValueEntities in CategoryPropertyValues.GroupBy(x => x.Name))
            {
                var propValues = propValueEntities.OrderBy(x => x.Id).Select(x => x.ToModel(AbstractTypeFactory <PropertyValue> .TryCreateInstance())).ToList();
                var property   = category.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.Category;
                    category.Properties.Add(property);
                }
                property.Values = propValues;
            }
            return(category);
        }
Пример #5
0
        public virtual Category ToModel(Category category)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            category.Id           = Id;
            category.CreatedBy    = CreatedBy;
            category.CreatedDate  = CreatedDate;
            category.ModifiedBy   = ModifiedBy;
            category.ModifiedDate = ModifiedDate;
            category.OuterId      = OuterId;

            category.Code     = Code;
            category.Name     = Name;
            category.Priority = Priority;
            category.TaxType  = TaxType;

            category.CatalogId = CatalogId;

            category.ParentId = ParentCategoryId;
            category.IsActive = IsActive;

            category.Links  = OutgoingLinks.Select(x => x.ToModel(new CategoryLink())).ToList();
            category.Images = Images.OrderBy(x => x.SortOrder).Select(x => x.ToModel(AbstractTypeFactory <Image> .TryCreateInstance())).ToList();
            // SeoInfos
            category.SeoInfos   = SeoInfos.Select(x => x.ToModel(AbstractTypeFactory <SeoInfo> .TryCreateInstance())).ToList();
            category.Properties = Properties.Select(x => x.ToModel(AbstractTypeFactory <Property> .TryCreateInstance()))
                                  .OrderBy(x => x.Name)
                                  .ToList();
            foreach (var property in category.Properties)
            {
                property.IsReadOnly = property.Type != PropertyType.Category;
            }
            //transform property value into transient properties
            if (!CategoryPropertyValues.IsNullOrEmpty())
            {
                var propertyValues = CategoryPropertyValues.OrderBy(x => x.DictionaryItem?.SortOrder)
                                     .ThenBy(x => x.Name)
                                     .SelectMany(pv => pv.ToModel(AbstractTypeFactory <PropertyValue> .TryCreateInstance()).ToList());

                var transientInstanceProperties = propertyValues.GroupBy(pv => pv.PropertyName).Select(values =>
                {
                    var property       = AbstractTypeFactory <Property> .TryCreateInstance();
                    property.Type      = PropertyType.Category;
                    property.Name      = values.Key;
                    property.ValueType = values.FirstOrDefault().ValueType;
                    property.Values    = values.ToList();
                    foreach (var propValue in property.Values)
                    {
                        propValue.Property = property;
                    }
                    return(property);
                }).OrderBy(x => x.Name).ToList();

                foreach (var transientInstanceProperty in transientInstanceProperties)
                {
                    var existSelfProperty = category.Properties.FirstOrDefault(x => x.IsSame(transientInstanceProperty, PropertyType.Category));
                    if (existSelfProperty == null)
                    {
                        category.Properties.Add(transientInstanceProperty);
                    }
                    else
                    {
                        //Just only copy values for existing self property
                        existSelfProperty.Values = transientInstanceProperty.Values;
                    }
                }
            }
            return(category);
        }
Пример #6
0
        public virtual Category ToModel(Category category)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

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

            category.Code     = Code;
            category.Name     = Name;
            category.Priority = Priority;
            category.TaxType  = TaxType;

            category.CatalogId = CatalogId;

            category.ParentId = ParentCategoryId;
            category.IsActive = IsActive;

            category.Links  = OutgoingLinks.Select(x => x.ToModel(new CategoryLink())).ToList();
            category.Images = Images.OrderBy(x => x.SortOrder).Select(x => x.ToModel(AbstractTypeFactory <Image> .TryCreateInstance())).ToList();

            category.Properties = new List <Property>();

            //Load self properties
            var selfProperties = Properties.Select(x => x.ToModel(AbstractTypeFactory <Property> .TryCreateInstance())).ToList();

            //load self category property values and transform then to transient properties
            if (!CategoryPropertyValues.IsNullOrEmpty())
            {
                var propertyValues = CategoryPropertyValues.OrderBy(x => x.DictionaryItem?.SortOrder)
                                     .ThenBy(x => x.Name)
                                     .SelectMany(pv => pv.ToModel(AbstractTypeFactory <PropertyValue> .TryCreateInstance()).ToList());

                category.Properties = propertyValues.GroupBy(pv => pv.PropertyName).Select(values =>
                {
                    var property       = AbstractTypeFactory <Property> .TryCreateInstance();
                    property.Name      = values.Key;
                    property.ValueType = values.FirstOrDefault().ValueType;
                    property.Values    = values.ToList();
                    return(property);
                }).ToList();
            }
            //Then try to inherit self transient properties without meta-informations from self properties
            foreach (var selfProperty in selfProperties)
            {
                var existTransientProperty = category.Properties.FirstOrDefault(x => x.IsSame(selfProperty, PropertyType.Product, PropertyType.Variation));
                if (existTransientProperty != null)
                {
                    existTransientProperty.TryInheritFrom(selfProperty);
                }
                else
                {
                    category.Properties.Add(selfProperty);
                }
            }

            return(category);
        }