Пример #1
0
 public ActionResult UpdateAds(AdsDTO model)
 {
     if (!ModelState.IsValid)
     {
         ViewBag.ProcessState = General.Messages.EmptyArea;
     }
     else
     {
         if (model.AdsImage != null)
         {
             HttpPostedFileBase postedFile = model.AdsImage;
             string             ext        = Path.GetExtension(postedFile.FileName);
             if (ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".gif")
             {
                 Bitmap userImage    = new Bitmap(postedFile.InputStream);
                 Bitmap resizedImage = new Bitmap(userImage);
                 string uniqueNumber = Guid.NewGuid().ToString();
                 string fileName     = uniqueNumber + postedFile.FileName;
                 resizedImage.Save(Server.MapPath("~/Areas/Admin/Content/AdsImages/" + fileName));
                 model.ImagePath = fileName;
             }
         }
         string oldImagePath = bll.UpdateAds(model);
         if (model.AdsImage != null) // There is new image.
         {
             string oldImageFullPath = Server.MapPath("~/Areas/Admin/Content/AdsImages/" + oldImagePath);
             if (System.IO.File.Exists(oldImageFullPath))
             {
                 System.IO.File.Delete(oldImageFullPath);
             }
         }
         ViewBag.ProcessState = General.Messages.AddSuccess;
     }
     return(View(model));
 }