//上传头像
 public ActionResult Upload()
 {
     try
     {
         HttpFileCollectionBase files = Request.Files;
         HttpPostedFileBase     file  = files[0];
         //获取文件名后缀
         string extName = VirtualPathUtility.GetExtension(file.FileName).ToLower();
         //获取保存目录的物理路径
         if (System.IO.Directory.Exists(Server.MapPath("/images/face/")) == false)//如果不存在就创建images文件夹
         {
             System.IO.Directory.CreateDirectory(Server.MapPath("/images/face/"));
         }
         string path = Server.MapPath("/images/face/"); //path为某个文件夹的绝对路径,不要直接保存到数据库
         //    string path = "F:\\TgeoSmart\\Image\\";
         //生成新文件的名称,guid保证某一时刻内图片名唯一(文件不会被覆盖)
         string fileNewName = Guid.NewGuid().ToString();
         string ImageUrl    = path + fileNewName + extName;
         //SaveAs将文件保存到指定文件夹中
         file.SaveAs(ImageUrl);
         //此路径为相对路径,只有把相对路径保存到数据库中图片才能正确显示(不加~为相对路径)
         string url = "\\/images/face/\\" + fileNewName + extName;
         if (!string.IsNullOrEmpty(url)) //修改数据库
         {
             CMS_User userFilter = new CMS_User();
             userFilter.uid = Convert.ToInt32(Session["userID"]);
             var list = CMS_User_BLL.Find(userFilter);
             list[0].face = fileNewName + extName;
             CMS_User_BLL.Edit(list[0]);
         }
         return(Json(new
         {
             Result = true,
             Data = url
         }));
     }
     catch (Exception exception)
     {
         return(Json(new
         {
             Result = false,
             exception.Message
         }));
     }
 }
Пример #2
0
 public ActionResult Edit(int uid)
 {
     try
     {
         CMS_User userFilter = new CMS_User();
         userFilter.uid = uid;
         Pagination      pagination = CMS_User_BLL.Find(userFilter, 10, 1);
         List <CMS_User> list       = pagination.rows as List <CMS_User>;
         if (list[0].admin == 0)
         {
             list[0].admin = 1;
         }
         else if (list[0].admin == 1)
         {
             list[0].admin = 0;
         }
         var count = CMS_User_BLL.Edit(list[0]);
         return(Json(count, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }