Beispiel #1
0
        public void DeleteImage(ProductImage productImage)
        {
            if (_productImageRepository.IsExists(productImage))
            {
                _productImageRepository.DeleteProductImageReference(productImage);

                var product = _productRepository.GetProduct(productImage.ProductId);

                if (product.ImageId == productImage.ImageId)
                {
                    var resultProductImage = _productImageRepository.GetImages(productImage.ProductId).FirstOrDefault();
                    product.ImageId = resultProductImage != null ? resultProductImage.ImageId : 0;

                    _productRepository.UpdateProduct(product);
                }

                _imageRepository.DeleteImage(productImage.ImageId);
            }
        }