public virtual Member ToModel(Member member)
        {
            if (member == null)
            {
                throw new ArgumentNullException(nameof(member));
            }

            member.Id           = Id;
            member.CreatedBy    = CreatedBy;
            member.CreatedDate  = CreatedDate;
            member.ModifiedBy   = ModifiedBy;
            member.ModifiedDate = ModifiedDate;
            member.MemberType   = MemberType;
            member.Name         = Name;
            member.OuterId      = OuterId;
            member.Status       = Status;

            member.Addresses = Addresses.OrderBy(x => x.Id).Select(x => x.ToModel(AbstractTypeFactory <Address> .TryCreateInstance())).ToList();
            member.Emails    = Emails.OrderBy(x => x.Id).Select(x => x.Address).ToList();
            member.Notes     = Notes.OrderBy(x => x.Id).Select(x => x.ToModel(new Note())).ToList();
            member.Phones    = Phones.OrderBy(x => x.Id).Select(x => x.Number).ToList();
            member.Groups    = Groups.OrderBy(x => x.Id).Select(x => x.Group).ToList();
            member.SeoInfos  = SeoInfos.Select(x => x.ToModel(AbstractTypeFactory <SeoInfo> .TryCreateInstance())).ToList();

            member.DynamicProperties = DynamicPropertyObjectValues.GroupBy(x => x.PropertyId).Select(x =>
            {
                var property    = AbstractTypeFactory <DynamicObjectProperty> .TryCreateInstance();
                property.Id     = x.Key;
                property.Name   = x.FirstOrDefault()?.PropertyName;
                property.Values = x.Select(v => v.ToModel(AbstractTypeFactory <DynamicPropertyObjectValue> .TryCreateInstance())).ToArray();
                return(property);
            }).ToArray();

            return(member);
        }
        public virtual void Patch(MemberEntity target)
        {
            target.Name       = Name;
            target.MemberType = MemberType;
            target.OuterId    = OuterId;
            target.Status     = Status;

            if (!Phones.IsNullCollection())
            {
                var phoneComparer = AnonymousComparer.Create((PhoneEntity x) => x.Number);
                Phones.Patch(target.Phones, phoneComparer, (sourcePhone, targetPhone) => targetPhone.Number = sourcePhone.Number);
            }

            if (!Emails.IsNullCollection())
            {
                var addressComparer = AnonymousComparer.Create((EmailEntity x) => x.Address);
                Emails.Patch(target.Emails, addressComparer, (sourceEmail, targetEmail) => targetEmail.Address = sourceEmail.Address);
            }

            if (!Groups.IsNullCollection())
            {
                var groupComparer = AnonymousComparer.Create((MemberGroupEntity x) => x.Group);
                Groups.Patch(target.Groups, groupComparer, (sourceGroup, targetGroup) => targetGroup.Group = sourceGroup.Group);
            }

            if (!Addresses.IsNullCollection())
            {
                Addresses.Patch(target.Addresses, (sourceAddress, targetAddress) => sourceAddress.Patch(targetAddress));
            }

            if (!Notes.IsNullCollection())
            {
                var noteComparer = AnonymousComparer.Create((NoteEntity x) => x.Id ?? x.Body);
                Notes.Patch(target.Notes, noteComparer, (sourceNote, targetNote) => sourceNote.Patch(targetNote));
            }

            if (!MemberRelations.IsNullCollection())
            {
                var relationComparer = AnonymousComparer.Create((MemberRelationEntity x) => x.AncestorId);
                MemberRelations.Patch(target.MemberRelations, relationComparer, (sourceRel, targetRel) => { /*Nothing todo*/ });
            }

            if (!SeoInfos.IsNullCollection())
            {
                SeoInfos.Patch(target.SeoInfos, (sourceSeoInfo, targetSeoInfo) => sourceSeoInfo.Patch(targetSeoInfo));
            }

            if (!DynamicPropertyObjectValues.IsNullCollection())
            {
                DynamicPropertyObjectValues.Patch(target.DynamicPropertyObjectValues, (sourceDynamicPropertyObjectValues, targetDynamicPropertyObjectValues) => sourceDynamicPropertyObjectValues.Patch(targetDynamicPropertyObjectValues));
            }
        }
Esempio n. 3
0
        public virtual object Clone()
        {
            var result = MemberwiseClone() as Category;

            result.SeoInfos   = SeoInfos?.Select(x => x.Clone()).OfType <SeoInfo>().ToList();
            result.Children   = Children?.Select(x => x.Clone()).OfType <Category>().ToList();
            result.Outlines   = Outlines?.Select(x => x.Clone()).OfType <Outline>().ToList();
            result.Parents    = Parents?.Select(x => x.Clone()).OfType <Category>().ToArray();
            result.Properties = Properties?.Select(x => x.Clone()).OfType <Property>().ToList();
            result.Links      = Links?.Select(x => x.Clone()).OfType <CategoryLink>().ToList();
            // result.Images = Images?.Select(x => x.Clone()).OfType<Image>().ToList(); // Intentionally temporary disabled due to memory overhead

            return(result);
        }
        public async Task <StoreEntity[]> GetStoresByIdsAsync(string[] ids)
        {
            var retVal = await Stores.Where(x => ids.Contains(x.Id))
                         .Include(x => x.Languages)
                         .Include(x => x.Currencies)
                         .Include(x => x.TrustedGroups)
                         .ToArrayAsync();

            var fulfillmentCenters = StoreFulfillmentCenters.Where(x => ids.Contains(x.StoreId)).ToArrayAsync();
            var seoInfos           = SeoInfos.Where(x => ids.Contains(x.StoreId)).ToArrayAsync();

            await Task.WhenAll(fulfillmentCenters, seoInfos);

            return(retVal);
        }
Esempio n. 5
0
        public virtual object Clone()
        {
            var result = MemberwiseClone() as CatalogProduct;

            result.SeoInfos               = SeoInfos?.Select(x => x.Clone()).OfType <SeoInfo>().ToList();
            result.Images                 = Images?.Select(x => x.Clone()).OfType <Image>().ToList();
            result.Assets                 = Assets?.Select(x => x.Clone()).OfType <Asset>().ToList();
            result.Properties             = Properties?.Select(x => x.Clone()).OfType <Property>().ToList();
            result.Associations           = Associations?.Select(x => x.Clone()).OfType <ProductAssociation>().ToList();
            result.ReferencedAssociations = ReferencedAssociations?.Select(x => x.Clone()).OfType <ProductAssociation>().ToList();
            result.Reviews                = Reviews?.Select(x => x.Clone()).OfType <EditorialReview>().ToList();
            result.Links      = Links?.Select(x => x.Clone()).OfType <CategoryLink>().ToList();
            result.Variations = Variations?.Select(x => x.Clone()).OfType <Variation>().ToList();

            return(result);
        }
Esempio n. 6
0
        public virtual object Clone()
        {
            var result = MemberwiseClone() as CatalogProduct;

            // result.Catalog = (Catalog)Catalog?.Clone(); // Intentionally temporary disabled due to memory overhead
            // result.Category = (Category)Category?.Clone(); // Intentionally temporary disabled due to memory overhead
            result.SeoInfos               = SeoInfos?.Select(x => x.Clone()).OfType <SeoInfo>().ToList();
            result.Images                 = Images?.Select(x => x.Clone()).OfType <Image>().ToList();
            result.Assets                 = Assets?.Select(x => x.Clone()).OfType <Asset>().ToList();
            result.Properties             = Properties?.Select(x => x.Clone()).OfType <Property>().ToList();
            result.Associations           = Associations?.Select(x => x.Clone()).OfType <ProductAssociation>().ToList();
            result.ReferencedAssociations = ReferencedAssociations?.Select(x => x.Clone()).OfType <ProductAssociation>().ToList();
            result.Reviews                = Reviews?.Select(x => x.Clone()).OfType <EditorialReview>().ToList();
            result.Links      = Links?.Select(x => x.Clone()).OfType <CategoryLink>().ToList();
            result.Variations = Variations?.Select(x => x.Clone()).OfType <Variation>().ToList();
            // result.Outlines = Outlines?.Select(x => x.Clone()).OfType<Outline>().ToList(); // Intentionally temporary disabled due to memory overhead

            return(result);
        }
Esempio n. 7
0
        public virtual object Clone()
        {
            var result = base.MemberwiseClone() as CatalogProduct;

            if (SeoInfos != null)
            {
                result.SeoInfos = SeoInfos.Select(x => x.Clone()).OfType <SeoInfo>().ToList();
            }
            if (Images != null)
            {
                result.Images = Images.Select(x => x.Clone()).OfType <Image>().ToList();
            }
            if (Assets != null)
            {
                result.Assets = Assets.Select(x => x.Clone()).OfType <Asset>().ToList();
            }
            if (Properties != null)
            {
                result.Properties = Properties.Select(x => x.Clone()).OfType <Property>().ToList();
            }
            if (Associations != null)
            {
                result.Associations = Associations.Select(x => x.Clone()).OfType <ProductAssociation>().ToList();
            }
            if (ReferencedAssociations != null)
            {
                result.ReferencedAssociations = ReferencedAssociations.Select(x => x.Clone()).OfType <ProductAssociation>().ToList();
            }
            if (Reviews != null)
            {
                result.Reviews = Reviews.Select(x => x.Clone()).OfType <EditorialReview>().ToList();
            }
            if (Links != null)
            {
                result.Links = Links.Select(x => x.Clone()).OfType <CategoryLink>().ToList();
            }
            if (Variations != null)
            {
                result.Variations = Variations.Select(x => x.Clone()).OfType <Variation>().ToList();
            }
            return(result);
        }
Esempio n. 8
0
File: Image.cs Progetto: HydAu/vc
        public object Clone()
        {
            var retVal = new Image();

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

            retVal.Name         = Name;
            retVal.Url          = Url;
            retVal.Group        = Group;
            retVal.SortOrder    = SortOrder;
            retVal.LanguageCode = LanguageCode;
            retVal.IsInherited  = IsInherited;
            if (SeoInfos != null)
            {
                retVal.SeoInfos = SeoInfos.Select(x => x.Clone()).OfType <SeoInfo>().ToList();
            }
            return(retVal);
        }
        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;
            target.ExcludedProperties = ExcludedProperties;

            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));
            }

            if (!SeoInfos.IsNullCollection())
            {
                SeoInfos.Patch(target.SeoInfos, (sourceSeoInfo, targetSeoInfo) => sourceSeoInfo.Patch(targetSeoInfo));
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Merge from other product, without any deletion, only update and create allowed
        ///
        /// </summary>
        /// <param name="product"></param>
        public void MergeFrom(CatalogProduct product)
        {
            Id = product.Id;

            var imgComparer = AnonymousComparer.Create((Image x) => x.Url);

            Images = Images.Concat(product.Images).Distinct(imgComparer).ToList();

            var assetComparer = AnonymousComparer.Create((Asset x) => x.Url);

            Assets = Assets.Concat(product.Assets).Distinct(assetComparer).ToList();

            var reviewsComparer = AnonymousComparer.Create((EditorialReview x) => string.Join(":", x.ReviewType, x.LanguageCode));

            Reviews = Reviews.Concat(product.Reviews).Distinct(reviewsComparer).ToList();

            var properyValueComparer = AnonymousComparer.Create((PropertyValue x) => x.PropertyName);

            PropertyValues = product.PropertyValues.Concat(PropertyValues).Distinct(properyValueComparer).ToList();

            var seoComparer = AnonymousComparer.Create((SeoInfo x) => string.Join(":", x.SemanticUrl, x.LanguageCode));

            SeoInfos = SeoInfos.Concat(product.SeoInfos).Distinct(seoComparer).ToList();
        }
Esempio n. 11
0
        /// <summary>
        /// Merge from other product, without any deletion, only update and create allowed
        ///
        /// </summary>
        /// <param name="product"></param>
        public void MergeFrom(CatalogProduct product)
        {
            Id = product.Id;

            if (string.IsNullOrEmpty(Code))
            {
                Code = product.Code;
            }

            if (string.IsNullOrEmpty(Name))
            {
                Name = product.Name;
            }

            if (string.IsNullOrEmpty(CategoryId))
            {
                CategoryId = product.CategoryId;
            }

            if (Category == null || (Category != null && string.IsNullOrEmpty(Category.Path)))
            {
                Category = product.Category;
            }

            if (string.IsNullOrEmpty(ProductType))
            {
                ProductType = product.ProductType;
            }

            if (string.IsNullOrEmpty(Vendor))
            {
                Vendor = product.Vendor;
            }

            if (string.IsNullOrEmpty(Gtin))
            {
                Gtin = product.Gtin;
            }

            if (string.IsNullOrEmpty(OuterId))
            {
                OuterId = product.OuterId;
            }

            if (string.IsNullOrEmpty(PackageType))
            {
                PackageType = product.PackageType;
            }

            if (string.IsNullOrEmpty(ManufacturerPartNumber))
            {
                ManufacturerPartNumber = product.ManufacturerPartNumber;
            }

            if (string.IsNullOrEmpty(WeightUnit))
            {
                WeightUnit = product.WeightUnit;
            }

            if (string.IsNullOrEmpty(MeasureUnit))
            {
                MeasureUnit = product.MeasureUnit;
            }

            if (string.IsNullOrEmpty(DownloadType))
            {
                DownloadType = product.DownloadType;
            }

            if (string.IsNullOrEmpty(ShippingType))
            {
                ShippingType = product.ShippingType;
            }

            if (string.IsNullOrEmpty(TaxType))
            {
                TaxType = product.TaxType;
            }

            Weight ??= product.Weight;
            Height ??= product.Height;
            Length ??= product.Length;
            Width ??= product.Width;

            MaxQuantity ??= product.MaxQuantity;
            MinQuantity ??= product.MinQuantity;

            if (Priority == default)
            {
                Priority = product.Priority;
            }

            EndDate ??= product.EndDate;

            foreach (var image in product.Images)
            {
                var existedImage = Images.FirstOrDefault(x => x.Url.Equals(image.Url, StringComparison.InvariantCultureIgnoreCase));
                if (existedImage != null)
                {
                    existedImage.Id = image.Id;
                }
                else
                {
                    Images.Add(image);
                }
            }

            var assetComparer = AnonymousComparer.Create((Asset x) => x.Url);

            Assets = Assets.Concat(product.Assets).Distinct(assetComparer).ToList();

            var reviewsComparer = AnonymousComparer.Create((EditorialReview x) => string.Join(":", x.ReviewType, x.LanguageCode, x.Content));

            Reviews = Reviews.Concat(product.Reviews).Distinct(reviewsComparer).ToList();

            // Merge Properties - leave properties that are not presented in CSV and add all from the CSV (with merging metadata and replacing existing ones)
            var propertyComparer          = AnonymousComparer.Create((Property x) => x.Name);
            var skippedExistingProperties = new List <Property>();

            foreach (var property in Properties.OfType <CsvProperty>())
            {
                var existingProperty = product.Properties.FirstOrDefault(x => propertyComparer.Equals(x, property));
                if (existingProperty != null)
                {
                    property.MergeFrom(existingProperty);
                    skippedExistingProperties.Add(existingProperty);
                }
            }

            Properties = Properties.Where(x => !x.Name.IsNullOrEmpty())
                         .Concat(product.Properties
                                 .Where(x => !skippedExistingProperties.Any(existingProperty => propertyComparer.Equals(x, existingProperty))))
                         .ToList();

            //merge seo infos
            var seoComparer = AnonymousComparer.Create((SeoInfo x) => string.Join(":", x.SemanticUrl, x.LanguageCode?.ToLower(), x.StoreId));

            foreach (var seoInfo in SeoInfos.OfType <CsvSeoInfo>())
            {
                var existingSeoInfo = product.SeoInfos.FirstOrDefault(x => seoComparer.Equals(x, seoInfo));
                if (existingSeoInfo != null)
                {
                    seoInfo.MergeFrom(existingSeoInfo);
                    product.SeoInfos.Remove(existingSeoInfo);
                }
            }
            SeoInfos = SeoInfos.Where(x => !x.SemanticUrl.IsNullOrEmpty()).Concat(product.SeoInfos).ToList();
        }
        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.ExcludedProperties = ExcludedProperties?.Select(x => new ExcludedProperty(x)).ToList();

            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);
        }
        /// <summary>
        /// Merge from other product, without any deletion, only update and create allowed
        ///
        /// </summary>
        /// <param name="product"></param>
        public void MergeFrom(CatalogProduct product)
        {
            Id = product.Id;

            if (string.IsNullOrEmpty(Code))
            {
                Code = product.Code;
            }

            if (string.IsNullOrEmpty(Name))
            {
                Name = product.Name;
            }

            if (string.IsNullOrEmpty(CategoryId))
            {
                CategoryId = product.CategoryId;
            }

            if (Category == null || (Category != null && string.IsNullOrEmpty(Category.Path)))
            {
                Category = product.Category;
            }

            if (string.IsNullOrEmpty(ProductType))
            {
                ProductType = product.ProductType;
            }

            if (string.IsNullOrEmpty(Vendor))
            {
                Vendor = product.Vendor;
            }

            var imgComparer = AnonymousComparer.Create((Image x) => x.Url);

            Images = Images.Concat(product.Images).Distinct(imgComparer).ToList();

            var assetComparer = AnonymousComparer.Create((Asset x) => x.Url);

            Assets = Assets.Concat(product.Assets).Distinct(assetComparer).ToList();

            var reviewsComparer = AnonymousComparer.Create((EditorialReview x) => string.Join(":", x.ReviewType, x.LanguageCode));

            Reviews = Reviews.Concat(product.Reviews).Distinct(reviewsComparer).ToList();

            var properyValueComparer = AnonymousComparer.Create((PropertyValue x) => x.PropertyName);

            foreach (var propertyValue in PropertyValues)
            {
                var array = product.PropertyValues.Where(x => properyValueComparer.Equals(x, propertyValue)).ToArray();
                foreach (var productPropertyValue in array)
                {
                    product.PropertyValues.Remove(productPropertyValue);
                }
            }
            PropertyValues = product.PropertyValues.Concat(PropertyValues).ToList();

            //merge seo infos
            var seoComparer = AnonymousComparer.Create((SeoInfo x) => string.Join(":", x.SemanticUrl, x.LanguageCode?.ToLower(), x.StoreId));

            foreach (var seoInfo in SeoInfos.OfType <CsvSeoInfo>())
            {
                var existingSeoInfo = product.SeoInfos.FirstOrDefault(x => seoComparer.Equals(x, seoInfo));
                if (existingSeoInfo != null)
                {
                    seoInfo.MergeFrom(existingSeoInfo);
                    product.SeoInfos.Remove(existingSeoInfo);
                }
            }
            SeoInfos = SeoInfos.Where(x => !x.SemanticUrl.IsNullOrEmpty()).Concat(product.SeoInfos).ToList();
        }
Esempio n. 14
0
        public virtual void Patch(ItemEntity target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            target.IsBuyable      = IsBuyable;
            target.IsActive       = IsActive;
            target.TrackInventory = TrackInventory;
            target.MinQuantity    = MinQuantity;
            target.MaxQuantity    = MaxQuantity;
            target.EnableReview   = EnableReview;

            target.CatalogId              = CatalogId;
            target.CategoryId             = CategoryId;
            target.Name                   = Name;
            target.Code                   = Code;
            target.ManufacturerPartNumber = ManufacturerPartNumber;
            target.Gtin                   = Gtin;
            target.ProductType            = ProductType;
            target.MaxNumberOfDownload    = MaxNumberOfDownload;
            target.DownloadType           = DownloadType;
            target.HasUserAgreement       = HasUserAgreement;
            target.DownloadExpiration     = DownloadExpiration;
            target.Vendor                 = Vendor;
            target.TaxType                = TaxType;
            target.WeightUnit             = WeightUnit;
            target.Weight                 = Weight;
            target.MeasureUnit            = MeasureUnit;
            target.PackageType            = PackageType;
            target.Height                 = Height;
            target.Length                 = Length;
            target.Width                  = Width;
            target.ShippingType           = ShippingType;
            target.Priority               = Priority;
            target.ParentId               = ParentId;
            target.StartDate              = StartDate;
            target.EndDate                = EndDate;

            #region Assets
            if (!Assets.IsNullCollection())
            {
                Assets.Patch(target.Assets, (sourceAsset, targetAsset) => sourceAsset.Patch(targetAsset));
            }
            #endregion

            #region Images
            if (!Images.IsNullCollection())
            {
                Images.Patch(target.Images, (sourceImage, targetImage) => sourceImage.Patch(targetImage));
            }
            #endregion

            #region ItemPropertyValues
            if (!ItemPropertyValues.IsNullCollection())
            {
                ItemPropertyValues.Patch(target.ItemPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
            }
            #endregion

            #region Links
            if (!CategoryLinks.IsNullCollection())
            {
                var categoryItemRelationComparer = AnonymousComparer.Create((CategoryItemRelationEntity x) => string.Join(":", x.CatalogId, x.CategoryId));
                CategoryLinks.Patch(target.CategoryLinks, categoryItemRelationComparer,
                                    (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
            }
            #endregion

            #region EditorialReviews
            if (!EditorialReviews.IsNullCollection())
            {
                EditorialReviews.Patch(target.EditorialReviews, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
            }
            #endregion

            #region Association
            if (!Associations.IsNullCollection())
            {
                Associations.Patch(target.Associations, new AssociationEntityComparer(), (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
            }
            #endregion

            #region SeoInfos
            if (!SeoInfos.IsNullCollection())
            {
                SeoInfos.Patch(target.SeoInfos, (sourceSeoInfo, targetSeoInfo) => sourceSeoInfo.Patch(targetSeoInfo));
            }
            #endregion
        }
Esempio n. 15
0
        public virtual CatalogProduct ToModel(CatalogProduct product, bool convertChildrens = true, bool convertAssociations = true)
        {
            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

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

            product.CatalogId              = CatalogId;
            product.CategoryId             = CategoryId;
            product.Code                   = Code;
            product.DownloadExpiration     = DownloadExpiration;
            product.DownloadType           = DownloadType;
            product.EnableReview           = EnableReview;
            product.EndDate                = EndDate;
            product.Gtin                   = Gtin;
            product.HasUserAgreement       = HasUserAgreement;
            product.Height                 = Height;
            product.IsActive               = IsActive;
            product.IsBuyable              = IsBuyable;
            product.Length                 = Length;
            product.MainProductId          = ParentId;
            product.ManufacturerPartNumber = ManufacturerPartNumber;
            product.MaxNumberOfDownload    = MaxNumberOfDownload;
            product.MaxQuantity            = (int)MaxQuantity;
            product.MeasureUnit            = MeasureUnit;
            product.MinQuantity            = (int)MinQuantity;
            product.Name                   = Name;
            product.PackageType            = PackageType;
            product.Priority               = Priority;
            product.ProductType            = ProductType;
            product.ShippingType           = ShippingType;
            product.StartDate              = StartDate;
            product.TaxType                = TaxType;
            product.TrackInventory         = TrackInventory;
            product.Vendor                 = Vendor;
            product.Weight                 = Weight;
            product.WeightUnit             = WeightUnit;
            product.Width                  = Width;

            //Links
            product.Links = CategoryLinks.Select(x => x.ToModel(AbstractTypeFactory <CategoryLink> .TryCreateInstance())).ToList();
            //Images
            product.Images = Images.OrderBy(x => x.SortOrder).Select(x => x.ToModel(AbstractTypeFactory <Image> .TryCreateInstance())).ToList();
            //Assets
            product.Assets = Assets.OrderBy(x => x.CreatedDate).Select(x => x.ToModel(AbstractTypeFactory <Asset> .TryCreateInstance())).ToList();
            // EditorialReviews
            product.Reviews = EditorialReviews.Select(x => x.ToModel(AbstractTypeFactory <EditorialReview> .TryCreateInstance())).ToList();
            // SeoInfos
            product.SeoInfos = SeoInfos.Select(x => x.ToModel(AbstractTypeFactory <SeoInfo> .TryCreateInstance())).ToList();

            product.Properties = new List <Property>();
            if (convertAssociations)
            {
                // Associations
                product.Associations           = Associations.Select(x => x.ToModel(AbstractTypeFactory <ProductAssociation> .TryCreateInstance())).OrderBy(x => x.Priority).ToList();
                product.ReferencedAssociations = ReferencedAssociations.Select(x => x.ToReferencedAssociationModel(AbstractTypeFactory <ProductAssociation> .TryCreateInstance())).OrderBy(x => x.Priority).ToList();
            }

            //item property values
            if (!ItemPropertyValues.IsNullOrEmpty())
            {
                var propertyValues = ItemPropertyValues.OrderBy(x => x.DictionaryItem?.SortOrder)
                                     .ThenBy(x => x.Name)
                                     .SelectMany(pv => pv.ToModel(AbstractTypeFactory <PropertyValue> .TryCreateInstance()).ToList());

                product.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();
                    foreach (var propValue in property.Values)
                    {
                        propValue.Property = property;
                    }
                    return(property);
                }).OrderBy(x => x.Name).ToList();
            }

            if (Parent != null)
            {
                product.MainProduct = Parent.ToModel(AbstractTypeFactory <CatalogProduct> .TryCreateInstance(), false, convertAssociations);
            }

            if (convertChildrens)
            {
                // Variations
                product.Variations = new List <Variation>();
                foreach (var variation in Childrens)
                {
                    var productVariation = variation.ToModel(AbstractTypeFactory <Variation> .TryCreateInstance()) as Variation;
                    productVariation.MainProduct   = product;
                    productVariation.MainProductId = product.Id;
                    product.Variations.Add(productVariation);
                }
            }
            return(product);
        }