Пример #1
0
 public static void SaveFile(this Controller ctr, HttpPostedFileBase file, int id, string path)
 {
     if (!file.Empty())
     {
         string localPath = string.Format("~/{0}/{1}{2}", path, id, Path.GetExtension(file.FileName));
         if (UploadConfig.Enable)
         {
             file.SaveAs(ctr.Server.MapPath(localPath));
         }
     }
 }
Пример #2
0
        public ActionResult ModifyAvatar(HttpPostedFileBase image, string returnUrl)
        {
            if (image.Empty())
            {
                ViewBag.ErrorMessage = "No image upload.";
                ModelState.AddModelError("", ViewBag.ErrorMessage);
                return(ModifyAvatar(returnUrl));
            }
            //保存图片
            using (var db = new MKContext())
            {
                this.SaveFile(image, db.GetUserProfile(User.Identity.Name).Id, "Image/Avatar");
            }

            return(RedirectToLocal(returnUrl));
        }