public ActionResult AddCourse(Course model) { model.UserID = CurrentUser.ID; model.Time = DateTime.Now; db.Courses.Add(model); db.SaveChanges(); return RedirectToAction("CourseManager"); }
public ActionResult AddCourse(Course model, HttpPostedFileBase file) { model.UserID = CurrentUser.ID; model.Time = DateTime.Now; System.IO.Stream stream = file.InputStream; byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); stream.Close(); model.Picture = buffer; db.Courses.Add(model); db.SaveChanges(); string root = "~/Lessions/" + model.Title + "/"; var phicyPath = HostingEnvironment.MapPath(root); Directory.CreateDirectory(phicyPath); return RedirectToAction("CourseManager"); }
/// <summary> /// 显示课程截图 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult ShowPicture(int id) { Course course = new Course(); course = db.Courses.Find(id); if (course.Picture == null) { var path = Server.MapPath("~/Images/book.jpg"); return File(path, "image/jpg"); } else { return File(course.Picture, "image/jpg"); } }
/// <summary> /// 综合测试 /// </summary> /// <param name="cid"></param> /// <param name="rate"></param> /// <returns></returns> public ActionResult DoTest(int cid, double rate) { Course course = new Course(); course = db.Courses.Find(cid); if (rate > 0.6) { UserCourse userCourse = db.UserCourses.Where(uc => uc.UserID == CurrentUser.ID && uc.CourseID == cid).FirstOrDefault(); userCourse.IsFinisnCourse = true; userCourse.Time = DateTime.Now; Models.User user = new User(); user = db.Users.Find(CurrentUser.ID); user.Score += course.Credit; db.SaveChanges(); } return View(); }
public ActionResult CourseShow(int id) { Course course = new Course(); course = db.Courses.Find(id); ViewBag.Course = new vCourse(course); return View(); }
public ActionResult CoursesEdit(Course model) { Course course = new Course(); course = db.Courses.Find(model.ID); course.CourseTypeID = model.CourseTypeID; course.Title = model.Title; course.Description = model.Description; course.Authority = model.Authority; db.SaveChanges(); return RedirectToAction("CourseManager"); }
public ActionResult CoursesEdit(int id) { Course course = new Course(); List<TypeDictionary> courseTypes = new List<TypeDictionary>(); course = db.Courses.Find(id); courseTypes = db.TypeDictionaries.Where(td => td.FatherID == 0 && td.Belonger == TypeBelonger.课程).ToList(); var second = new List<TypeDictionary>(); second = db.TypeDictionaries.Where(td => td.FatherID == course.TypeDictionary.FatherID).ToList(); ViewBag.Second = second; ViewBag.Course = course; ViewBag.Types = courseTypes; return View(); }
public ActionResult CoursesDelete(int id) { Course course = new Course(); course = db.Courses.Find(id); db.Courses.Remove(course); db.SaveChanges(); return Content("ok"); }
public ActionResult AddLession(int id) { Course course = new Course(); course = db.Courses.Find(id); ViewBag.Course = course; return View(); }
public ActionResult CourseShow(int id) { CourseQuestion coursequestion = new CourseQuestion(); List<CourseQuestion> coursequestions = db.CourseQuestions.Where(cq => cq.CourseID == id).ToList(); List<vCourseQuestion> coursequestionlist = new List<vCourseQuestion>(); foreach (var item in coursequestions) { coursequestionlist.Add(new vCourseQuestion(item)); } ViewBag.CourseQuestions = coursequestionlist; Course course = new Course(); course = db.Courses.Find(id); ViewBag.Course = course; return View(); }