public ActionResult Yuntiku(string x) { YTK ytk = new YTK(); var files = Request.Files; var studentNo = Convert.ToInt32(this.User.Identity.Name); string fileName = studentNo + "/" + studentNo + "-" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "/"; if (files != null && files.Count > 0) { for (int i = 0; i < files.Count; i++) { var strs = files[i].FileName.Split('.'); ytk.uploadFilePath = "~/WorkSpances/YTK/" + fileName + "/"; var path = Server.MapPath(ytk.uploadFilePath); //如果路径不存在则创建 if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } ytk.studentNo = studentNo; string uploadFileName = Guid.NewGuid().ToString() + "." + strs[1].ToLower(); ytk.uploadFileName = uploadFileName; ytk.Describeyt = "无"; files[i].SaveAs(path + uploadFileName); } student.AddYTK(ytk); } return(Content("<script>alert('上传完成!');</script>")); }
/// <summary> /// 添加云题库 /// </summary> /// <param name="uploadFileName"></param> /// <returns></returns> public bool AddYTK(YTK ytk) { var file = new UploadFile() { UploadFileName = ytk.uploadFileName, UploadFilePath = ytk.uploadFilePath, UploadTime = DateTime.Now, Describe = ytk.Describeyt }; context.UploadFiles.Add(file); if (context.SaveChanges() > 0) { var uploadFileId = Convert.ToInt32((context.UploadFiles.Where(s => s.UploadFilePath == ytk.uploadFilePath).Select(m => m.UploadFileId).ToList())[0]); var yt = new Homework() { StudentNo = ytk.studentNo, HomeworkTypeId = 3, UploadFileId = uploadFileId }; context.Homework.Add(yt); if (context.SaveChanges() > 0) { return(true); } } return(false); }
public bool AddYTK(YTK ytk) { return(student.AddYTK(ytk)); }