Esempio n. 1
0
    protected void uxSetAsPrimayImageButton_Click(object sender, EventArgs e)
    {
        string     storeID  = new StoreRetriever().GetCurrentStoreID();
        LinkButton myButton = (LinkButton)sender;
        string     imageID  = myButton.CommandArgument;
        Product    product  = DataAccessContext.ProductRepository.GetOne(Culture.Null, ProductID, storeID);

        string originalFilePath;

        if (ProductID == "0")
        {
            ProductImageData.SetPrimary(imageID);
            ImageItem item = ProductImageData.FindItem(imageID);
            originalFilePath = item.LargeImage;
        }
        else
        {
            ProductImage oldPrimaryImage = new ProductImage();
            ProductImage newPrimaryImage = new ProductImage();
            foreach (ProductImage productImage in product.ProductImages)
            {
                if (productImage.ProductImageID == imageID)
                {
                    newPrimaryImage = productImage;
                }
                if (productImage.SortOrder == 0)
                {
                    oldPrimaryImage = productImage;
                }
            }

            SetProductImageOrder(product, oldPrimaryImage.ProductImageID, newPrimaryImage.SortOrder);
            SetProductImageOrder(product, newPrimaryImage.ProductImageID, 0);

            originalFilePath = newPrimaryImage.LargeImage;
        }

        using (ProductImageFile imageFile = ProductImageFile.Load(new FileManager(), Path.GetFileName(originalFilePath)))
        {
            if (ProductID == "0")
            {
                SaveSecondaryNoProduct(imageFile);
            }
            else
            {
                SaveSecondary(product, imageFile);
            }
        }

        if (!product.IsNull)
        {
            DataAccessContext.ProductRepository.Save(product);
        }

        uxMessage.DisplayMessage(Resources.ProductImageMessages.SetPrimarySuccess);

        uxStatusHidden.Value = "SetPrimary";
    }
Esempio n. 2
0
    private void SetNewPrimaryImageAfterDelete(string imageID)
    {
        ProductImageData.SetPrimary(imageID);
        ImageItem item1            = ProductImageData.FindItem(imageID);
        string    originalFilePath = item1.LargeImage;

        using (ProductImageFile imageFile = ProductImageFile.Load(new FileManager(), Path.GetFileName(originalFilePath)))
        {
            SaveSecondaryNoProduct(imageFile);
        }
    }
Esempio n. 3
0
 private void CrateDataSource()
 {
     _imageSource     = CreateTable("ProductImage");
     _tempImageSource = CreateTable("TempProductImage");
     if (ProductID == "0")
     {
         uxSecondaryImageHidden.Value = ProductImageData.SecondaryImagePath;
         foreach (ImageItem item in ProductImageData.GetAllItems())
         {
             CreateRow(
                 _tempImageSource, item.ProductImageID, 0,
                 item.RegularImage, item.LargeImage, item.ThumbnailImage,
                 item.ImageSize, item.SortOrder, item.IsZoom, item.IsEnlarge,
                 item.ImageWidth, item.ImageHeight, item.Locales[CurrentCulture].AltTag, item.Locales[CurrentCulture].TitleTag);
         }
     }
     else
     {
         Product product = DataAccessContext.ProductRepository.GetOne(CurrentCulture, ProductID, new StoreRetriever().GetCurrentStoreID());
         uxSecondaryImageHidden.Value = product.ImageSecondary;
         foreach (ProductImage productImage in product.ProductImages)
         {
             ProductImageLocale locale = productImage.Locales[CurrentCulture];
             using (ProductImageFile imageFile =
                        ProductImageFile.Load(new FileManager(), Path.GetFileName(productImage.LargeImage)))
             {
                 CreateRow(_tempImageSource, productImage.ProductImageID,
                           ConvertUtilities.ToInt32(product.ProductID),
                           productImage.RegularImage,
                           productImage.LargeImage,
                           productImage.ThumbnailImage,
                           ProductImageFile.GetImageSize(new FileManager(), productImage.LargeImage),
                           productImage.SortOrder,
                           productImage.IsZoom,
                           productImage.IsEnlarge,
                           imageFile.LargeImageWidth,
                           imageFile.LargeImageHeight,
                           locale.AltTag,
                           locale.TitleTag);
             }
         }
     }
 }
Esempio n. 4
0
    private void RemoveExistingProductImage(Product product, string imageID)
    {
        bool         deletePrimary        = false;
        ProductImage productImageToDelete = new ProductImage();

        foreach (ProductImage productimage in product.ProductImages)
        {
            if (productimage.ProductImageID == imageID)
            {
                DeleteImage(productimage.RegularImage, productimage.LargeImage, productimage.ThumbnailImage);
                if (productimage.SortOrder == 0)
                {
                    DeleteFile(product.ImageSecondary);
                    deletePrimary = true;
                }
                productImageToDelete = productimage;
            }
        }

        product.ProductImages.Remove(productImageToDelete);

        if (deletePrimary)
        {
            foreach (ProductImage productimage in product.ProductImages)
            {
                productimage.SortOrder = productimage.SortOrder - 1;
                if (productimage.SortOrder == 0)
                {
                    using (ProductImageFile imageFile = ProductImageFile.Load(new FileManager(), Path.GetFileName(productimage.LargeImage)))
                    {
                        SaveSecondary(product, imageFile);
                    }
                }
            }
        }
    }