コード例 #1
0
        public bool AddAdminFile(AdminFile f)
        {
            DBSession db = new DBSession();

            if (adfdal.Add(f) != null)
            {
                db.SaveChanges();
                return(true);
            }
            ;
            return(false);
        }
コード例 #2
0
        //
        // GET: /Upload/

        #region 管理员文件上传
        public ActionResult AdminFileUpLoad()
        {
            AdminFileService adfs = new AdminFileService();
            AdminFileDal     adfd = new AdminFileDal();
            Admin            ad   = (Admin)Session["admin"];
            var file = Request.Files["file"];

            if (file.ContentLength == 0)
            {
                return(Content("请选择要上传的文件"));
            }
            var filename = Request["filename"];

            IQueryable <AdminFile> iq = adfd.GetEntities(u => u.AdF_Name == filename);

            if (iq.Count() >= 1)
            {
                return(Content("此文件或文件名已存在"));
            }
            var       intro = Request["intro"];
            AdminFile adf   = new AdminFile();

            adf.AdF_Intro = intro;
            adf.AdF_Name  = filename;
            adf.Admin     = ad;
            adf.SubTime   = DateTime.Now;
            string s     = file.FileName;      //全路径的名字
            int    index = s.LastIndexOf("."); //获取最后面点的位置
            string hzm   = s.Substring(index); // 获取后缀名
            // string path = "/Upload/" + Guid.NewGuid().ToString() + hzm;   //防止命名相同
            string path = "/Upload/" + Guid.NewGuid().ToString() + filename + hzm;

            adf.Url = path;
            adfs.AddAdminFile(adf);
            file.SaveAs(Request.MapPath(path));
            return(Content("上传成功"));
        }