public ActionResult GetTeacherFile() { TeaFileService sdfser = new TeaFileService(); IQueryable <TeaFile> iq = sdfser.GetPageTeaFile(); IList <string> strl = new List <string>(); foreach (var item in iq) { string str = item.SubTime + "=" + item.TeaF_Name + "=" + item.Url; strl.Add(str); } string str1 = js.Serialize(strl); Response.Write(str1); Response.End(); return(View()); }
public ActionResult TeaFileUpLoad() { TeaFileService adfs = new TeaFileService(); TeaFileDal adfd = new TeaFileDal(); Teacher tea = (Teacher)Session["teacher"]; var file = Request.Files["file"]; if (file.ContentLength == 0) { return(Content("请选择要上传的文件")); } var filename = Request["filename"]; IQueryable <TeaFile> iq = adfd.GetEntities(u => u.Teacher.Tea_Id == tea.Tea_Id); var intro = Request["intro"]; TeaFile adf = new TeaFile(); // adf.Admin = ad; adf.TeaF_Intro = intro; adf.TeaF_Name = filename; adf.Teacher = tea; adf.SubTime = DateTime.Now; string s = file.FileName; //全路径的名字 int index = s.LastIndexOf("."); //获取最后面点的位置 string hzm = s.Substring(index); // 获取后缀名 string path = "/Upload/" + filename + Guid.NewGuid().ToString() + hzm; //防止命名相同 // string path = "/Upload/"+ filename + hzm; adf.Url = path; adfs.AddTeaFile(adf); //string path = "/Upload/" + file.FileName; //string activeDir = @"C:\myDir"; //string newPath = System.IO.Path.Combine(activeDir, "mySubDirOne"); //System.IO.Directory.CreateDirectory(newPath); file.SaveAs(Request.MapPath(path)); //return Content(s + " " + hzm + " " + path); return(Content("上传成功")); }
public ActionResult Login() { //加载admin文件 AdminFileService sdfser = new AdminFileService(); IQueryable <AdminFile> iq = sdfser.GetPageAdminFile(); IList <string> strl = new List <string>(); foreach (var item in iq) { string str = item.SubTime + "=" + item.AdF_Name + "=" + item.Url; strl.Add(str); } Session["strlist"] = strl; //加载老师文件 TeaFileService sdfser2 = new TeaFileService(); IQueryable <TeaFile> iq2 = sdfser2.GetPageTeaFile(); IList <string> strl2 = new List <string>(); foreach (var item in iq2) { string str = item.SubTime + "=" + item.TeaF_Name + "=" + item.Url; strl2.Add(str); } Session["strlist2"] = strl2; string role = Request["role"]; string num = Request["Num"]; string pwd = Request["Pwd"]; string vcode = Request["vCode"].Trim(); string sessionCode = (string)Session["validate"]; Session["validate"] = null; if (string.IsNullOrEmpty(sessionCode) || !String.Equals(vcode, sessionCode, StringComparison.CurrentCultureIgnoreCase)) { return(Content("验证码错误!")); } if (role == "student") { StudentService stus = new StudentService(); Student s = stus.StudentLoginByNumAndPwd(num, pwd); if (s != null) { Session["student"] = s; return(RedirectToAction("Index1", "Student")); } else { return(Content("学生用户名密码不正确1")); } } else if (role == "teacher") { TeacherService teas = new TeacherService(); Teacher t = teas.TeacherLoginByNumAndPwd(num, pwd); if (t != null) { Session["teacher"] = t; return(RedirectToAction("Index", "Teacher")); } else { return(Content("教师用户名密码不正确2")); } } else if (role == "admin") { AdminService adm = new AdminService(); Admin admin = new Admin(); Admin admin1 = adm.AdminLoginByNumAndPwd(num, pwd); if (admin1 != null) { Session["admin"] = admin1; return(RedirectToAction("Index", "Admin")); } else { return(Content("管理员用户名密码不正确")); } } return(Content("用户名密码不正确3")); }