コード例 #1
0
 public CategoriesController(ICategoryService categoryService,
                             ILoggerManager loggerManager,
                             IMapper mapper,
                             CategoryLinks dataShaper)
 {
     _categoryService = categoryService;
     _loggerManager   = loggerManager;
     _mapper          = mapper;
     _categoryLinks   = dataShaper;
 }
コード例 #2
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
        }
コード例 #3
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);
        }