protected void AddImageButton_Click(object sender, EventArgs e)
        {
            SaveImages();
            ProductImage image = new ProductImage();

            image.ProductId = _ProductId;
            image.ImageUrl  = string.Empty;
            image.Save();
            _Product.Images.Add(image);
            BindImages();
        }
 public IActionResult Post([FromBody] ProductImage image, [FromServices] IHostingEnvironment hosting)
 {
     image.Save(hosting);
     return(Ok("保存成功"));
 }
 protected void UploadButton_Click(object sender, EventArgs e)
 {
     if (UploadedFile.HasFile)
     {
         bool success = true;
         StoreSettingsManager settings = AbleContext.Current.Store.Settings;
         if (!BaseFileName.Text.Contains("."))
         {
             BaseFileName.Text += System.IO.Path.GetExtension(UploadedFile.FileName);
         }
         string safeFileName = string.Empty;
         safeFileName = FileHelper.GetSafeBaseImageName(BaseFileName.Text, true);
         if (!string.IsNullOrEmpty(safeFileName) && FileHelper.IsExtensionValid(safeFileName, AbleContext.Current.Store.Settings.FileExt_Assets))
         {
             //save the image to do the resizing work
             if (!Resize.Checked)
             {
                 //JUST SAVE THE IMAGE AND ASSOCIATE WITH PRODUCT
                 string tempImagePath = FileHelper.BaseImagePath + safeFileName;
                 UploadedFile.SaveAs(tempImagePath);
                 ProductImage newImage = new ProductImage();
                 newImage.ProductId = _ProductId;
                 newImage.ImageUrl  = FileHelper.BaseImageUrlPath + safeFileName;
                 newImage.Moniker   = Moniker.Text.Trim();
                 newImage.Save();
             }
             else
             {
                 string tempImagePath = FileHelper.BaseImagePath + Guid.NewGuid().ToString("N") + ".jpg";
                 UploadedFile.SaveAs(tempImagePath);
                 if (FileHelper.IsImageFile(tempImagePath))
                 {
                     using (System.Drawing.Image originalImage = System.Drawing.Image.FromFile(tempImagePath))
                     {
                         FileHelper.WriteImageFile(originalImage, FileHelper.BaseImagePath + safeFileName, AlwaysConvert.ToInt(CustomWidth.Text), AlwaysConvert.ToInt(CustomHeight.Text), MaintainAspectRatio.Checked, AlwaysConvert.ToInt(Quality.Text));
                         ProductImage newImage = new ProductImage();
                         newImage.ProductId = _ProductId;
                         newImage.ImageUrl  = FileHelper.BaseImageUrlPath + safeFileName;
                         newImage.Moniker   = Moniker.Text.Trim();
                         newImage.Save();
                     }
                 }
                 else
                 {
                     success = false;
                     CustomValidator invalidFile = new CustomValidator();
                     invalidFile.Text         = "*";
                     invalidFile.ErrorMessage = "You did not upload a valid file.";
                     invalidFile.IsValid      = false;
                     phInvalidFile.Controls.Add(invalidFile);
                 }
                 try
                 {
                     if (System.IO.File.Exists(tempImagePath))
                     {
                         System.IO.File.Delete(tempImagePath);
                     }
                 }
                 catch (Exception ex)
                 {
                     Logger.Warn("Could not delete temporary image file " + tempImagePath, ex);
                 }
             }
             if (success)
             {
                 Response.Redirect("AdditionalImages.aspx?ProductId=" + _ProductId.ToString());
             }
         }
         else
         {
             CustomValidator filetype = new CustomValidator();
             filetype.IsValid           = false;
             filetype.ControlToValidate = "BaseFileName";
             filetype.ErrorMessage      = "'" + safeFileName + "' is not a valid file name.";
             filetype.Text = "*";
             phValidFiles.Controls.Add(filetype);
         }
     }
 }