/// <summary> /// 删除用户 /// </summary> /// <param name="deleteUserInfoID"></param> /// <returns></returns> public ActionResult DeleteUser(string deleteUserInfoID, string Name) { var UIdsName = Name.Split(','); List<string> deleteUName = new List<string>(); foreach (var item in UIdsName) { deleteUName.Add(item); } if (deleteUName.Contains(Session["UserName"].ToString())) { return Content("含有正在使用的用户,禁止删除"); } if (string.IsNullOrEmpty(deleteUserInfoID)) { return Content("请选择您要删除的数据"); } var idsStr = deleteUserInfoID.Split(','); List<int> deleteIDList = new List<int>(); foreach (var ID in idsStr) { deleteIDList.Add(Convert.ToInt32(ID)); } using (EasyUIDemoDBEntities db = new EasyUIDemoDBEntities()) { foreach (var ID in deleteIDList) { var users = db.UserInfo.Where(p => p.ID == ID).FirstOrDefault(); db.UserInfo.Remove(users); } db.SaveChanges(); } return Content("OK"); }
/// <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> /// 获取用户的所有信息 /// </summary> /// <returns></returns> public ActionResult GetAllUserInfo() { int pageIndex = Request["page"] == null ? 1 : int.Parse(Request["page"]); int pageSize = Request["rows"] == null ? 10 : int.Parse(Request["rows"]); int total = 0; using (EasyUIDemoDBEntities db = new EasyUIDemoDBEntities()) { var temp = from u in db.UserInfo select u; total = temp.Count(); var users = temp.OrderByDescending(s => s.ID) .Skip<UserInfo>((pageIndex - 1) * pageSize).Take<UserInfo>(pageSize); var data = new { total = total, rows = users.ToList<UserInfo>() }; return Json(data); } }
/// <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 = "用户名密码错误,请您检查" }); } } }
/// <summary> /// 绑定用户数据 /// </summary> /// <param name="ID"></param> /// <returns></returns> public ActionResult GetBindDetails(int ID) { using (EasyUIDemoDBEntities db = new EasyUIDemoDBEntities()) { var BindIDForUpdateTextBox = db.UserInfo.Where(u => u.ID == ID).FirstOrDefault(); return Json(BindIDForUpdateTextBox, JsonRequestBehavior.AllowGet); } }