Exemple #1
0
        public JsonResult DeleteConfirmed(int?id)
        {
            Message msg = new Message();

            if (id == null)
            {
                msg.MessageStatus = "false";
                msg.MessageInfo   = "找不到ID";
            }
            else
            {
                ImgandFile imgandfile = db.ImgandFiles.Find(id);
                try
                {
                    FileTools.DeleteFile(imgandfile.FilePath);
                    db.ImgandFiles.Remove(imgandfile);

                    db.SaveChanges();
                    msg.MessageStatus = "true";
                    msg.MessageInfo   = "删除成功";
                }
                catch {
                    db.ImgandFiles.Remove(imgandfile);

                    db.SaveChanges();
                    msg.MessageStatus = "true";
                    msg.MessageInfo   = "文件删除失败,数据删除成功,请联系管理员手动删除文件!";
                }
            }


            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
 public ActionResult Edit([Bind(Include = "ID,FileCategroy,FileTitle,FileInfo,FilePath,HrefUrl")] ImgandFile imgandfile)
 {
     if (ModelState.IsValid)
     {
         db.Entry(imgandfile).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(imgandfile));
 }
Exemple #3
0
        public ActionResult Create([Bind(Include = "ID,FileCategroy,FileTitle,FileInfo,FilePath,HrefUrl")] ImgandFile imgandfile)
        {
            if (ModelState.IsValid)
            {
                db.ImgandFiles.Add(imgandfile);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(imgandfile));
        }
Exemple #4
0
        // GET: /ImgFile/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ImgandFile imgandfile = db.ImgandFiles.Find(id);

            if (imgandfile == null)
            {
                return(HttpNotFound());
            }
            return(View(imgandfile));
        }