/// <summary> /// 添加用户 /// </summary> /// <param name="userinfo"></param> /// <returns></returns> public ActionResult AddUser(UserInfo userinfo) { userinfo.CreateTime = DateTime.Now; using (EasyUIDemoDBEntities db = new EasyUIDemoDBEntities()) { db.UserInfo.Add(userinfo); db.SaveChanges(); } return Content("OK"); }
/// <summary> /// 重新基类在Action执行之前的事情 /// </summary> /// <param name="filterContext">重写方法的参数</param> protected override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); //得到用户登录的信息 CurrentUserInfo = Session["UserInfo"] as UserInfo; //判断用户是否为空 if (CurrentUserInfo == null) { Response.Redirect(Url.Content("~/Login/Login")); } }
/// <summary> /// 处理登录的信息 /// </summary> /// <param name="userInfo"></param> /// <returns></returns> public JsonResult CheckUserLogin(UserInfo userInfo) { using (EasyUIDemoDBEntities db = new EasyUIDemoDBEntities()) { //linq查询 var users = from p in db.UserInfo where p.Name == userInfo.Name && p.Password == userInfo.Password && p.Enable == true select p; if (users.Count() > 0) { userInfo = users.FirstOrDefault(); Session["UserInfo"] = userInfo; Response.Cookies["UserName"].Value = userInfo.Name; Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(7); return Json(new { result = "success", content = "" }); } else { return Json(new { result = "error", content = "用户名密码错误,请您检查" }); } } }