/// <summary> /// 添加用户 /// </summary> /// <param name="user">实体类(用户)</param> /// <returns>添加成功的标志</returns> public ActionResult AddUser(BaseUser user) { user.Code = Guid.NewGuid().ToString(); //获取数据的查询码 user.QuickQuery = user.UserName; //用户来源 user.UserFrom = "添加"; //默认系统识别的是汉语 user.Lang = "汉语"; //默认是职员 user.IsStaff = (Int32?)StaffEnum.OK; //默认显示信息 user.IsVisible = (Int32?)VisibleEnum.OK; //默认用户有效 user.Enabled = (Int32?)EnabledEnum.OK; //默认添加的用户已经经过审核 user.AuditStatus = "已审核"; //默认没有伪删除 user.DeletionStateCode = (Int32?)DeletionStateCodeEnum.Normal; //创建用户日期 user.CreateOn = DateTime.Parse(DateTime.Now.ToString()); BaseUser loginUser = Session["UserInfo"] as BaseUser; //添加此用户的信息 user.CreateUserID = loginUser.Code; user.CreateBy = loginUser.UserName; //添加实体 _userInfoService.AddEntity(user); return Content("OK"); }
/// <summary> /// 重写基类在Action执行之前的方法 /// </summary> /// <param name="filterContext"></param> protected override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); //获取登录用户 为空则跳转 CurrentUser = Session["UserInfo"] as BaseUser; if (CurrentUser==null) { Response.Redirect("/Login"); } }
/// <summary> /// 用户登录验证 /// </summary> /// <param name="userInfo">实体类(用户)</param> /// <param name="code">验证码</param> /// <returns></returns> public ActionResult ChkUserInfo(BaseUser userInfo,string code) { string sCode = this.TempData["vCode"] == null ? new Guid().ToString() : this.TempData["vCode"].ToString(); //去掉验证码 避免暴力破解 this.Session["vCode"] = new Guid(); if (sCode!=code) { return Content("验证码输入错误!"); } var loginUser = _userInfoService.ChkUserInfo(userInfo); if (loginUser!=null) { //保存登录用户信息 Session["UserInfo"] = loginUser; return Content("OK"); } else { return Content("用户名密码错误!"); } }
/// <summary> /// 用于向 BaseUser EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToBaseUser(BaseUser baseUser) { base.AddObject("BaseUser", baseUser); }
/// <summary> /// 创建新的 BaseUser 对象。 /// </summary> /// <param name="id">ID 属性的初始值。</param> public static BaseUser CreateBaseUser(global::System.Int32 id) { BaseUser baseUser = new BaseUser(); baseUser.ID = id; return baseUser; }
/// <summary> /// 用户的删除还原 /// </summary> /// <param name="user">实体类(用户)</param> /// <param name="ID">用户ID组</param> /// <param name="Flag">伪删除 还原标志</param> /// <returns></returns> public ActionResult DeleteUsers(BaseUser user, string ID, string Flag) { BaseUser loginUser = Session["UserInfo"] as BaseUser; List<int> delIds = new List<int>(); if (ID.Length > 1) //选择多条 { string[] idstrs = ID.Split(','); foreach (var item in idstrs) { delIds.Add(int.Parse(item)); } } else //只选择一条 { delIds.Add(int.Parse(ID)); } if (Flag == "not") //伪删除 { foreach (var item in delIds) { var removeUser = _userInfoService.LoadEntities(u => u.ID == item).FirstOrDefault(); removeUser.DeletionStateCode = 1; //更改用户的信息 removeUser.ModifiedUserID = loginUser.Code; removeUser.ModifiedBy = loginUser.UserName; removeUser.ModifirdOn = DateTime.Now; _userInfoService.UpdateEntity(removeUser); } return Content("OK"); } if (Flag == "back") //还原 { foreach (var item in delIds) { var restoreUser = _userInfoService.LoadEntities(u => u.ID == item).FirstOrDefault(); restoreUser.DeletionStateCode = 0; //更改用户的信息 restoreUser.ModifiedUserID = loginUser.Code; restoreUser.ModifiedBy = loginUser.UserName; restoreUser.ModifirdOn = DateTime.Now; _userInfoService.UpdateEntity(restoreUser); } return Content("OK"); } else { if (_userInfoService.DeleteUsers(delIds) > 0) { return Content("OK"); } return Content("Error"); } }
/// <summary> /// 修改用户信息 /// </summary> /// <param name="user">实体类(用户)</param> /// <returns></returns> public ActionResult UpdateUser(BaseUser user) { //首先根据传递过来的参数查询出要修改的信息 var editUser = _userInfoService.LoadEntities(c => c.ID == user.ID).FirstOrDefault(); if (editUser == null) { return Content("错误信息,请您检查"); } //对用户的信息进行修改 editUser.UserName = user.UserName; editUser.RealName = user.RealName; editUser.QuickQuery = user.UserName; editUser.Email = user.Email; editUser.SecurityLevel = user.SecurityLevel; editUser.Gender = user.Gender; editUser.Birthday = user.Birthday; editUser.Mobile = user.Mobile; editUser.Telephone = user.Telephone; editUser.QICQ = user.QICQ; editUser.SortCode = user.SortCode; editUser.IsStaff = user.IsStaff; editUser.IsVisible = user.IsVisible; editUser.Enabled = user.Enabled; editUser.AuditStatus = user.AuditStatus; editUser.Description = user.Description; editUser.ModifirdOn = DateTime.Parse(DateTime.Now.ToString()); BaseUser loginUser = Session["UserInfo"] as BaseUser; editUser.ModifiedUserID = loginUser.Code; editUser.ModifiedBy = loginUser.UserName; editUser.ModifirdOn = DateTime.Now; if (_userInfoService.UpdateEntity(editUser)) { return Content("OK"); } return Content("Error"); }