コード例 #1
0
        public dataModel.Item[] GetItemByIds(string[] itemIds, coreModel.ItemResponseGroup respGroup = coreModel.ItemResponseGroup.ItemLarge)
        {
            if (itemIds == null)
            {
                throw new ArgumentNullException("categoriesIds");
            }

            if (!itemIds.Any())
            {
                return(new dataModel.Item[] { });
            }
            //Used breaking query EF performance concept https://msdn.microsoft.com/en-us/data/hh949853.aspx#8
            var retVal = Items.Include(x => x.Images).Where(x => itemIds.Contains(x.Id)).ToArray();

            //Load product catalogs separately
            var catalogIds = retVal.Select(x => x.CatalogId).Distinct().ToArray();
            var catalogs   = Catalogs.Include(x => x.CatalogLanguages).Where(x => catalogIds.Contains(x.Id)).ToArray();

            //Load product categories separately
            var categoryIds = retVal.Select(x => x.CategoryId).Where(x => !String.IsNullOrEmpty(x)).Distinct().ToArray();
            var categories  = Categories.Where(x => categoryIds.Contains(x.Id)).ToArray();

            if ((respGroup & coreModel.ItemResponseGroup.Links) == coreModel.ItemResponseGroup.Links)
            {
                var relations = CategoryItemRelations.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }
            if ((respGroup & coreModel.ItemResponseGroup.ItemProperties) == coreModel.ItemResponseGroup.ItemProperties)
            {
                var propertyValues = PropertyValues.Where(x => itemIds.Contains(x.ItemId)).ToArray();
                //Load categories with all properties for property inheritance
                categories = GetCategoriesByIds(categoryIds, coreModel.CategoryResponseGroup.WithProperties);
            }
            if ((respGroup & coreModel.ItemResponseGroup.ItemAssets) == coreModel.ItemResponseGroup.ItemAssets)
            {
                var assets = Assets.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }
            if ((respGroup & coreModel.ItemResponseGroup.ItemEditorialReviews) == coreModel.ItemResponseGroup.ItemEditorialReviews)
            {
                var editorialReviews = EditorialReviews.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }
            if ((respGroup & coreModel.ItemResponseGroup.Variations) == coreModel.ItemResponseGroup.Variations)
            {
                var variationIds = Items.Where(x => itemIds.Contains(x.ParentId)).Select(x => x.Id).ToArray();
                //For variations loads only info and images
                var variations = Items.Include(x => x.Images).Where(x => variationIds.Contains(x.Id)).ToArray();
                //load variations property values separately
                var variationPropertyValues = PropertyValues.Where(x => variationIds.Contains(x.ItemId)).ToArray();
            }
            if ((respGroup & coreModel.ItemResponseGroup.ItemAssociations) == coreModel.ItemResponseGroup.ItemAssociations)
            {
                var assosiationGroups = AssociationGroups.Include(x => x.Associations).ToArray();
                var assosiatedItemIds = assosiationGroups.SelectMany(x => x.Associations).Select(x => x.ItemId).Distinct().ToArray();
                var assosiationItems  = GetItemByIds(assosiatedItemIds, coreModel.ItemResponseGroup.ItemInfo);
            }
            //Load parents
            var parentIds = retVal.Where(x => x.Parent == null && x.ParentId != null).Select(x => x.ParentId).ToArray();
            var parents   = GetItemByIds(parentIds, respGroup);

            return(retVal);
        }
コード例 #2
0
        public dataModel.Item[] GetItemByIds(string[] itemIds, coreModel.ItemResponseGroup respGroup = coreModel.ItemResponseGroup.ItemLarge)
        {
            if (!itemIds.Any())
            {
                return(new dataModel.Item[] { });
            }

            //Used breaking query EF performance concept https://msdn.microsoft.com/en-us/data/hh949853.aspx#8
            var retVal = Items.Include(x => x.Catalog).Include(x => x.Category).Include(x => x.Images).Where(x => itemIds.Contains(x.Id)).ToArray();


            if ((respGroup & coreModel.ItemResponseGroup.Categories) == coreModel.ItemResponseGroup.Categories)
            {
                var relations = CategoryItemRelations.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }
            if ((respGroup & coreModel.ItemResponseGroup.ItemProperties) == coreModel.ItemResponseGroup.ItemProperties)
            {
                var propertyValues = ItemPropertyValues.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }
            if ((respGroup & coreModel.ItemResponseGroup.ItemAssets) == coreModel.ItemResponseGroup.ItemAssets)
            {
                var assets = Assets.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }
            if ((respGroup & coreModel.ItemResponseGroup.ItemEditorialReviews) == coreModel.ItemResponseGroup.ItemEditorialReviews)
            {
                var editorialReviews = EditorialReviews.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }
            if ((respGroup & coreModel.ItemResponseGroup.ItemAssociations) == coreModel.ItemResponseGroup.ItemAssociations)
            {
                var associations = Associations.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }
            if ((respGroup & coreModel.ItemResponseGroup.Variations) == coreModel.ItemResponseGroup.Variations)
            {
                var variationIds = Items.Where(x => itemIds.Contains(x.ParentId)).Select(x => x.Id).ToArray();
                var variations   = GetItemByIds(variationIds, respGroup);
            }
            //Load parents
            var parentIds = retVal.Where(x => x.Parent == null && x.ParentId != null).Select(x => x.ParentId).ToArray();
            var parents   = GetItemByIds(parentIds, respGroup);

            return(retVal);
        }
コード例 #3
0
        public dataModel.Item[] GetItemByIds(string[] itemIds, coreModel.ItemResponseGroup respGroup = coreModel.ItemResponseGroup.ItemLarge)
        {
            if (itemIds == null)
            {
                throw new ArgumentNullException("itemIds");
            }

            if (!itemIds.Any())
            {
                return(new dataModel.Item[] { });
            }

            // Use breaking query EF performance concept https://msdn.microsoft.com/en-us/data/hh949853.aspx#8
            var retVal         = Items.Include(x => x.Images).Where(x => itemIds.Contains(x.Id)).ToArray();
            var propertyValues = PropertyValues.Where(x => itemIds.Contains(x.ItemId)).ToArray();

            if (respGroup.HasFlag(coreModel.ItemResponseGroup.Outlines))
            {
                respGroup |= coreModel.ItemResponseGroup.Links;
            }

            if (respGroup.HasFlag(coreModel.ItemResponseGroup.Links))
            {
                var relations = CategoryItemRelations.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }

            if (respGroup.HasFlag(coreModel.ItemResponseGroup.ItemAssets))
            {
                var assets = Assets.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }

            if (respGroup.HasFlag(coreModel.ItemResponseGroup.ItemEditorialReviews))
            {
                var editorialReviews = EditorialReviews.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }

            if (respGroup.HasFlag(coreModel.ItemResponseGroup.Variations))
            {
                // TODO: Call GetItemByIds for variations recursively (need to measure performance and data amount first)

                var variationIds = Items.Where(x => itemIds.Contains(x.ParentId)).Select(x => x.Id).ToArray();

                // Always load info, images and property values for variations
                var variations = Items.Include(x => x.Images).Where(x => variationIds.Contains(x.Id)).ToArray();
                var variationPropertyValues = PropertyValues.Where(x => variationIds.Contains(x.ItemId)).ToArray();

                if (respGroup.HasFlag(coreModel.ItemResponseGroup.ItemAssets))
                {
                    var variationAssets = Assets.Where(x => variationIds.Contains(x.ItemId)).ToArray();
                }

                if (respGroup.HasFlag(coreModel.ItemResponseGroup.ItemEditorialReviews))
                {
                    var variationEditorialReviews = EditorialReviews.Where(x => variationIds.Contains(x.ItemId)).ToArray();
                }
            }

            if (respGroup.HasFlag(coreModel.ItemResponseGroup.ItemAssociations))
            {
                var assosiations         = Associations.Where(x => itemIds.Contains(x.ItemId)).ToArray();
                var assosiatedProductIds = assosiations.Where(x => x.AssociatedItemId != null)
                                           .Select(x => x.AssociatedItemId).Distinct().ToArray();

                var assosiatedItems = GetItemByIds(assosiatedProductIds, coreModel.ItemResponseGroup.ItemInfo | coreModel.ItemResponseGroup.ItemAssets);
            }

            // Load parents
            var parentIds = retVal.Where(x => x.Parent == null && x.ParentId != null).Select(x => x.ParentId).ToArray();
            var parents   = GetItemByIds(parentIds, respGroup);

            return(retVal);
        }
コード例 #4
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())
            {
                CategoryLinks.Patch(target.CategoryLinks, new 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())
            {
                var associationComparer = AnonymousComparer.Create((AssociationEntity x) => x.AssociationType + ":" + x.AssociatedItemId + ":" + x.AssociatedCategoryId);
                Associations.Patch(target.Associations, associationComparer,
                                   (sourceAssociation, targetAssociation) => sourceAssociation.Patch(targetAssociation));
            }
            #endregion
        }
コード例 #5
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.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();

            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
            product.PropertyValues = ItemPropertyValues
                                     .OrderBy(x => x.DictionaryItem?.SortOrder)
                                     .ThenBy(x => x.Name)
                                     .SelectMany(x => x.ToModel(AbstractTypeFactory <PropertyValue> .TryCreateInstance())).ToList();

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

            if (convertChildrens)
            {
                // Variations
                product.Variations = new List <CatalogProduct>();
                foreach (var variation in Childrens)
                {
                    var productVariation = variation.ToModel(AbstractTypeFactory <CatalogProduct> .TryCreateInstance());
                    productVariation.MainProduct   = product;
                    productVariation.MainProductId = product.Id;
                    product.Variations.Add(productVariation);
                }
            }
            return(product);
        }
コード例 #6
0
        public dataModel.Item[] GetItemByIds(string[] itemIds, coreModel.ItemResponseGroup respGroup = coreModel.ItemResponseGroup.ItemLarge)
        {
            if (itemIds == null)
            {
                throw new ArgumentNullException("itemIds");
            }

            if (!itemIds.Any())
            {
                return(new dataModel.Item[] { });
            }

            // Use breaking query EF performance concept https://msdn.microsoft.com/en-us/data/hh949853.aspx#8
            var retVal         = Items.Include(x => x.Images).Where(x => itemIds.Contains(x.Id)).ToArray();
            var propertyValues = PropertyValues.Where(x => itemIds.Contains(x.ItemId)).ToArray();

            // Load product catalogs separately
            var catalogIds = retVal.Select(x => x.CatalogId).Distinct().ToArray();
            var catalogs   = Catalogs.Include(x => x.CatalogLanguages).Where(x => catalogIds.Contains(x.Id)).ToArray();

            // Load product categories separately
            var categoryIds            = retVal.Select(x => x.CategoryId).Where(x => !string.IsNullOrEmpty(x)).Distinct().ToArray();
            var categoriesReponseGroup = coreModel.CategoryResponseGroup.WithParents;

            if (respGroup.HasFlag(coreModel.ItemResponseGroup.Outlines))
            {
                categoriesReponseGroup |= coreModel.CategoryResponseGroup.WithLinks;
            }

            if (respGroup.HasFlag(coreModel.ItemResponseGroup.ItemProperties))
            {
                // Load categories with all properties for property inheritance
                categoriesReponseGroup |= coreModel.CategoryResponseGroup.WithProperties;
            }

            var categories = GetCategoriesByIds(categoryIds, categoriesReponseGroup);

            if (respGroup.HasFlag(coreModel.ItemResponseGroup.Links) || respGroup.HasFlag(coreModel.ItemResponseGroup.Outlines))
            {
                var relations = CategoryItemRelations.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }

            // Load all properties meta information and data for inheritance from parent categories and catalog
            if (respGroup.HasFlag(coreModel.ItemResponseGroup.ItemProperties))
            {
                // Load catalogs with properties for products not belongs to any category (EF auto populated all Catalog nav properties for all objects)
                foreach (var catalogId in retVal.Where(x => x.CategoryId == null).Select(x => x.CatalogId))
                {
                    var catalog = GetCatalogById(catalogId);
                }
            }

            if (respGroup.HasFlag(coreModel.ItemResponseGroup.ItemAssets))
            {
                var assets = Assets.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }

            if (respGroup.HasFlag(coreModel.ItemResponseGroup.ItemEditorialReviews))
            {
                var editorialReviews = EditorialReviews.Where(x => itemIds.Contains(x.ItemId)).ToArray();
            }

            if (respGroup.HasFlag(coreModel.ItemResponseGroup.Variations))
            {
                var variationIds = Items.Where(x => itemIds.Contains(x.ParentId)).Select(x => x.Id).ToArray();
                // For variations load only info and images
                var variations = Items.Include(x => x.Images).Include(x => x.Assets).Where(x => variationIds.Contains(x.Id)).ToArray();
                // Load variations property values separately
                var variationPropertyValues = PropertyValues.Where(x => variationIds.Contains(x.ItemId)).ToArray();
            }

            if (respGroup.HasFlag(coreModel.ItemResponseGroup.ItemAssociations))
            {
                var assosiationGroups = AssociationGroups.Include(x => x.Associations).ToArray();
                var assosiatedItemIds = assosiationGroups.SelectMany(x => x.Associations).Select(x => x.ItemId).Distinct().ToArray();
                var assosiationItems  = GetItemByIds(assosiatedItemIds, coreModel.ItemResponseGroup.ItemInfo);
            }

            // Load parents
            var parentIds = retVal.Where(x => x.Parent == null && x.ParentId != null).Select(x => x.ParentId).ToArray();
            var parents   = GetItemByIds(parentIds, respGroup);

            return(retVal);
        }