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); } }