예제 #1
0
        /// <summary>
        /// 添加上机练习
        /// </summary>
        /// <param name="lx"></param>
        /// <returns></returns>
        public bool AddLianXi(LianXi lx)
        {
            //插入文件信息
            var file = new UploadFile()
            {
                UploadTime     = DateTime.Now,
                UploadFileName = lx.UploadFileNamelx,
                Describe       = lx.Describelx,
                UploadFilePath = lx.UploadFilePath
            };

            context.UploadFiles.Add(file);
            //如果插入文件成功则继续插入作业信息
            if (context.SaveChanges() > 0)
            {
                var uploadFileId = Convert.ToInt32((context.UploadFiles.Where(s => s.UploadFilePath == lx.UploadFilePath).Select(m => m.UploadFileId).ToList())[0]);
                //int uploadFileId = Convert.ToInt32();
                var lianXi = new Homework()
                {
                    StudentNo      = lx.StudentNo,
                    ChapterId      = lx.ChapterId,
                    HomeworkTypeId = lx.HomeworkTypeId,
                    Speed          = lx.Speedlx,
                    UploadFileId   = uploadFileId
                };
                context.Homework.Add(lianXi);
                if (context.SaveChanges() > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        /// <summary>
        /// 上机练习上传
        /// </summary>
        /// <param name="lx"></param>
        /// <param name="uploadFilelx"></param>
        /// <returns></returns>
        public ActionResult Lianxi(LianXi lx, HttpPostedFileBase uploadFilelx)
        {
            lx.HomeworkTypeId = 2;
            lx.StudentNo      = Convert.ToInt32(this.User.Identity.Name);
            //设置文件名
            string fileName = lx.StudentNo + "/" + lx.StudentNo + "-" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Millisecond + ".zip";
            //文件保存路径
            string path = Server.MapPath("~/WorkSpances/SJLX/" + lx.StudentNo + "/");

            //如果路径不存在则创建
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string uploadFilePath   = "~/WorkSpances/SJLX/" + fileName;
            string uploadFilePathRe = Server.MapPath(uploadFilePath);

            lx.UploadFileNamelx = fileName;
            uploadFilelx.SaveAs(uploadFilePathRe);
            lx.UploadFilePath = uploadFilePath;
            student.AddLianXi(lx);
            return(Content("<script>alert('上传成功!');location.href='" + Url.Action("Index") + "'</script>"));
        }
예제 #3
0
 public bool AddLianXi(LianXi lx)
 {
     return(student.AddLianXi(lx));
 }