private void RemoveNewProductImage(string imageID) { ImageItem item = ProductImageData.FindItem(imageID); if (item.SortOrder == 0) { DeleteFile(ProductImageData.SecondaryImagePath); ProductImageData.SecondaryImagePath = ""; if (uxGridProductImage.Rows.Count > 1) { string[] gridImageIDArray = new string[uxGridProductImage.Rows.Count - 1]; for (int i = 1; i < uxGridProductImage.Rows.Count; i++) { gridImageIDArray[i - 1] = ((HiddenField)uxGridProductImage.Rows[i].FindControl("uxImageIDHidden")).Value; } Array.Sort(gridImageIDArray); SetNewPrimaryImageAfterDelete(gridImageIDArray[0]); } } DeleteImage(item.RegularImage, item.LargeImage, item.ThumbnailImage); ProductImageData.RemoveItem(imageID); }
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"; }
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); } }