Exemplo n.º 1
0
        public ActionResult DelProject()
        {
            if (loginStatus() == false)
            {
                return Redirect("Login");
            }
            var response = new Dictionary<string,string>();
            var course = Request.Params["course"];
            var year = Request.Params["year"];
            var homework = Request.Params["homework"];
            var student = Request.Params["student"];
            if (course == null || year == null || homework == null || student == null)
            {
                response.Add("status", "failed");
                response.Add("error", "bad param");
            }
            var model = new ProjectModel();
            int row = model.DelProject(course, year, homework, student);
            if (row == 0)
            {
                response.Add("status", "failed");
                response.Add("error", "delete error");
            }
            Directory.Delete(Server.MapPath(string.Format("~/upload/project/{0}/{1}/{2}/{3}",course,year,homework,student)), true);
            response.Add("status", "success");

            return Json(response);
        }
Exemplo n.º 2
0
        public ActionResult AddProject()
        {
            if (loginStatus() == false)
            {
                return Redirect("Login");
            }
            var response = new Dictionary<string, string>();
            HttpPostedFileBase jar = Request.Files.Get("jar");
            HttpPostedFileBase html = Request.Files.Get("html");
            var baseSavePath = "~/upload/project";
            var savePath = "";
            var imgfilename = "";
            var jarfilename = "";
            var htmlname = "";
            var img_url = "";
            var html_url = "";
            var jar_url = "";
            if (html != null)
            {
                var model = new ProjectModel();
                HttpPostedFileBase image = Request.Files.Get("image");
                if (image!=null&&!checkFileExt(image.FileName, "jpg,gif,png,bmp"))
                {//检查图片后缀
                    response.Add("status", "failed");
                    response.Add("error", "only jpg,gif,png,bmp allowed!");
                    return Json(response);
                }
                if (jar != null && !checkFileExt(jar.FileName, "jar"))
                {//检测jar后缀
                    response.Add("status", "failed");
                    response.Add("error", "only jar file allowed!");
                    return Json(response);
                }


                if (checkFileExt(html.FileName, "html,htm"))
                {
                    var course = Request.Params["course"];
                    var year = Request.Params["year"];
                    var homework = Request.Params["homework"];
                    var student = Request.Params["student"];
                    var description = Request.Params["description"];
                    var visible = Request.Params["visible"];
                    if (course != null && year != null && homework != null&&student!=null)
                    {
                        savePath = string.Format("{0}/{1}/{2}/{3}/{4}", baseSavePath, course, year, homework,student);
                  

                        if (Directory.Exists(Server.MapPath(savePath)))//检查目录是否存在,存在则递归删除目录
                        {
                            
                            var project = model.getAllProject(course,year,homework,student);
                            if (project.id > 0)  //数据库中存在则删除数据
                            {
                                model.DelProject(course, year, homework, student);
                            }
                            Directory.Delete(Server.MapPath(savePath), true);
                        }
                        Directory.CreateDirectory(Server.MapPath(savePath));
                        //储存图片文件
                        
                       
                        if (image != null)
                        { //是否存在图片,存在则保存图片
                            //img_url = string.Format("{0}/{1}", savePath, image.FileName);
                            if (image.FileName.LastIndexOf('\\') != -1)  //IE文件获取文件名
                            {
                                imgfilename = image.FileName.Substring(image.FileName.LastIndexOf('\\') + 1, image.FileName.Length - 1 - image.FileName.LastIndexOf('\\'));
                            }
                            else
                            {
                                imgfilename = image.FileName;
                            }
                            img_url = string.Format("{0}/{1}", savePath, imgfilename);
                            image.SaveAs(Server.MapPath(img_url));
                            //image.SaveAs(Server.MapPath(img_url));
                        }

                        //储存jar文件
                        if (jar != null)
                        {
                            if (jar.FileName.LastIndexOf('\\') != -1) //IE文件获取文件名
                            {

                                jarfilename = jar.FileName.Substring(jar.FileName.LastIndexOf('\\') + 1, jar.FileName.Length - 1 - jar.FileName.LastIndexOf('\\'));

                            }
                            else
                            {
                                jarfilename = jar.FileName;
                            }
                            jar_url = string.Format("{0}/{1}", savePath, jarfilename);
                            jar.SaveAs(Server.MapPath(jar_url));
                        }
                        
                       //存储html文件
                       
                        if (html.FileName.LastIndexOf('\\') != -1)  //IE文件获取文件名
                        {
                            htmlname = html.FileName.Substring(html.FileName.LastIndexOf('\\') + 1, html.FileName.Length - 1 - html.FileName.LastIndexOf('\\'));
                        }
                        else
                        {
                            htmlname = html.FileName;
                        }
                        html_url = string.Format("{0}/{1}", savePath, htmlname);
                        html.SaveAs(Server.MapPath(html_url));
                        
                        if (visible != null && visible=="0")
                        {
                          var row =  model.AddProject(course, year, homework, student, html_url, jar_url, img_url, description,0);
                          if (row < 1)
                          {
                              response.Add("status", "failed");
                              response.Add("error", "insert error");
                              return Json(response);
                          }
                        }
                        else
                        {
                          var  row = model.AddProject(course, year, homework, student, html_url, jar_url, img_url, description);
                          if (row < 1)
                          {
                              response.Add("status", "failed");
                              response.Add("error", "insert error");
                              return Json(response);
                          }
                        }

                        

                        response.Add("status", "success");
                        
                    }
                    else
                    {
                        response.Add("status", "failed");
                        //response.Add("error", "course,year,homework can't be null");
                        response.Add("error", "only html,htm allowed!");
                    }
                }
                else
                {
                    response.Add("status", "failed");
                    response.Add("error", "only  *.java allowed");
                }
                
            }
            else
            {
                response.Add("status", "failed");
                response.Add("error", "no html");
            }
            return Json(response);
        }