Esempio n. 1
0
        public ActionResult Index(User userModel)
        {
            //根据页面传来的值,调用GetUser方法
            User user = GetUser(userModel);
            if (user == null)
            {
                return View();
            }
            //保存user 到cookie
            CourseCenter.Common.TakeCookie.SetCookie("userId", user.Id.ToString());

            if (user.Authority == "1")
            {
                //跳转到TeacherIndex方法
                return RedirectToAction("TeacherIndex");
            }

            if (user.Authority == "2")
            {
                //跳转到AdminIndex方法
                return RedirectToAction("AdminIndex");
            }
            if (user.Authority == "0")
            {
                //跳转到AdminIndex方法
                CourseCenter.Common.TakeCookie.SetCookie("EnterTime", DateTime.Today.ToString());
                return RedirectToAction("StudentIndex");
            }
            return View();
        }
Esempio n. 2
0
 /// <summary>
 /// 获取user的通用方法
 /// </summary>
 /// <param name="userModel"></param>
 /// <returns></returns>
 public User GetUser(User userModel)
 {
     User user = dbEntity.Admin.Where(a => a.Account == userModel.Account && a.Pwd == userModel.Pwd).FirstOrDefault();
     if (user != null)
     {
         return user;
     }
     user = dbEntity.TeacherInfo.Where(t => t.Account == userModel.Account && t.Pwd == userModel.Pwd ).FirstOrDefault();
     if (user != null)
     {
         return user;
     }
     user = dbEntity.StudentInfo.Where(s => s.Account == userModel.Account && s.Pwd == userModel.Pwd ).FirstOrDefault();
     return user;
 }