예제 #1
0
 public ActionResult File()
 {
     if (loginStatus() == false)
     {
         return Redirect("Login");
     }
    FileModel model = new FileModel();
    FileEntity[] fArray = model.getFiles(0, model.getTheNumberOfFile());
    ViewBag.fileList = fArray;
     return View();
 }
예제 #2
0
        public ActionResult Index()
        {
            int sid = getSid();
            if (sid == -1)
            {
                return Redirect("/Index/Index");
            }
            AnnouncementModel announceModel = new AnnouncementModel();
            ExamModel examModel = new ExamModel();
            FileModel fileModel = new FileModel();

            ViewBag.announcement = announceModel.getAnnouncements(0, 3);
            ViewBag.exam = examModel.getAvailableExam().Take(3);
            ViewBag.file = fileModel.getFiles(0, 3);
            assignTitle();
            return View();
        }
예제 #3
0
 public ActionResult File(int start=0,int size=10)
 {
     int sid = getSid();
     if (sid == -1)
     {
         return Redirect("/Index/Index");
     }
     var model = new FileModel();
     ViewBag.count = model.getTheNumberOfFile();
     ViewBag.data = model.getFiles(0, ViewBag.count);
     ViewBag.size = size;
     assignTitle();
     return View();
 }
예제 #4
0
        public ActionResult addFile()
        {
            if (loginStatus() == false)
            {
                return Redirect("Login");
            }
            Dictionary<string, String> ret = new Dictionary<string, string>();
            HttpPostedFileBase file = Request.Files.Get("file");
            string savepath = "/upload/file";
            var tmpfilename = "";
            if (file != null)
            {
                if (!Directory.Exists(Server.MapPath(savepath)))
                {
                    Directory.CreateDirectory(Server.MapPath(savepath));
                }
                if (file.FileName.LastIndexOf('\\') != -1)
                {
                    tmpfilename = file.FileName.Substring(file.FileName.LastIndexOf('\\') + 1, file.FileName.Length - 1 - file.FileName.LastIndexOf('\\'));
                }
                else
                {
                    tmpfilename = file.FileName;
                }

                file.SaveAs(Server.MapPath(string.Format("{0}/{1}", savepath,tmpfilename)));
                try
                {
                    exam_aspx.Models.FileModel model = new exam_aspx.Models.FileModel();
                    model.addFile(tmpfilename, string.Format("{0}/{1}", savepath, tmpfilename), file.ContentLength);
                    ret.Add("status", "success");
                }
                catch (Exception e)
                {
                    ret.Add("status", "failed");
                    ret.Add("error", "insert error!");
                }
                
                
            }
            else
            {
                ret.Add("status", "failed");
                ret.Add("error", "no file!");
            }
            return Json(ret);
        }
예제 #5
0
 public ActionResult delFile()
 {
     if (loginStatus() == false)
     {
         return Redirect("Login");
     }
     Dictionary<string, String> ret = new Dictionary<string, string>();
     try
     {
         int id = int.Parse(Request["id"]);
         exam_aspx.Models.FileModel model = new exam_aspx.Models.FileModel();
         FileEntity file = model.getFileById(id);
         if (file != null)
         {
             if (System.IO.File.Exists(Server.MapPath(file.path)))
             {
                 System.IO.File.Delete(Server.MapPath(file.path));
             }
         }
         int row = model.deleFile(id);
         if (row > 0)
         {
             ret.Add("status", "success");
             
         }
         else
         {
             ret.Add("status", "failed");
             ret.Add("error","delete failed!");
         }
         
     }
     catch (Exception e)
     {
         ret.Add("status", "failed");
         ret.Add("error", "bad param");
     }
     return Json(ret);
 }