Esempio n. 1
0
        private void PrepareProductImages(IEnumerable <ProductPicture> productPictures, ProductDto productDto)
        {
            if (productDto.Images == null)
            {
                productDto.Images = new List <ImageMappingDto>();
            }

            // Here we prepare the resulted dto image.
            foreach (var productPicture in productPictures)
            {
                var imageDto = PrepareImageDto(productPicture.Picture);

                if (imageDto != null)
                {
                    var productImageDto = new ImageMappingDto
                    {
                        Id         = productPicture.Id,
                        PictureId  = productPicture.PictureId,
                        Position   = productPicture.DisplayOrder,
                        Src        = imageDto.Src,
                        Attachment = imageDto.Attachment
                    };

                    productDto.Images.Add(productImageDto);
                }
            }
        }
Esempio n. 2
0
        protected ImageMappingDto PrepareProductImageDto(ProductPicture productPicture)
        {
            ImageMappingDto imageMapping = null;

            var picture = this._pictureService.GetPictureById(productPicture.PictureId);

            if (productPicture != null)
            {
                // We don't use the image from the passed dto directly
                // because the picture may be passed with src and the result should only include the base64 format.
                imageMapping = new ImageMappingDto
                {
                    //Attachment = Convert.ToBase64String(picture.PictureBinary),
                    Id         = productPicture.Id,
                    ProductIds = new List <int>()
                    {
                        productPicture.ProductId
                    },
                    PictureId = productPicture.PictureId,
                    Position  = productPicture.DisplayOrder,
                    MimeType  = picture.MimeType,
                    Src       = _pictureService.GetPictureUrl(productPicture.PictureId)
                };
            }

            return(imageMapping);
        }
Esempio n. 3
0
        private async Task PrepareProductImagesAsync(IEnumerable <ProductPicture> productPictures, ProductDto productDto)
        {
            if (productDto.Images == null)
            {
                productDto.Images = new List <ImageMappingDto>();
            }

            // Here we prepare the resulted dto image.
            foreach (var productPicture in productPictures)
            {
                var imageDto = await PrepareImageDtoAsync(await _pictureService.GetPictureByIdAsync(productPicture.PictureId));

                if (imageDto != null)
                {
                    var productImageDto = new ImageMappingDto
                    {
                        Id         = productPicture.Id,
                        PictureId  = productPicture.PictureId,
                        Position   = productPicture.DisplayOrder,
                        Src        = imageDto.Src,
                        Attachment = imageDto.Attachment
                    };

                    productDto.Images.Add(productImageDto);
                }
            }
        }
        private ProductAttributeValueDto PrepareProductAttributeValueDto(ProductAttributeValue productAttributeValue, Product product)
        {
            ProductAttributeValueDto productAttributeValueDto = null;

            if (productAttributeValue != null)
            {
                productAttributeValueDto = productAttributeValue.ToDto();
                if (productAttributeValue.ImageSquaresPictureId > 0)
                {
                    Picture  imageSquaresPicture = _pictureService.GetPictureById(productAttributeValue.ImageSquaresPictureId);
                    ImageDto imageDto            = PrepareImageDto(imageSquaresPicture);

                    if (imageDto != null)
                    {
                        ImageMappingDto productImageDto = new ImageMappingDto();
                        productImageDto.Id         = productAttributeValue.ImageSquaresPictureId;
                        productImageDto.Src        = imageDto.Src;
                        productImageDto.Attachment = imageDto.Attachment;

                        productAttributeValueDto.ImageSquaresImage = productImageDto;
                    }
                }

                if (productAttributeValue.PictureId > 0)
                {
                    // make sure that the picture is mapped to the product
                    // This is needed since if you delete the product picture mapping from the nopCommerce administrationthe
                    // then the attribute value is not updated and it will point to a picture that has been deleted
                    var productPicture = product.ProductPictures.FirstOrDefault(pp => pp.PictureId == productAttributeValue.PictureId);
                    if (productPicture != null)
                    {
                        productAttributeValueDto.ProductPictureId = productPicture.Id;
                    }
                }
            }

            return(productAttributeValueDto);
        }