public ActionResult UserLogin([FromBody] UserLoginDto userLogin) { var response = new ResponseDataHelper <UserInfoDto>(); try { var user = _userLogic.GetUserByLoginName(userLogin.LoginName); if (user == null) { response.ResponseCode = -1; response.ResponseMessage = "登录名不存在"; } else if (user.Password != userLogin.Password) { response.ResponseCode = -1; response.ResponseMessage = "密码不正确"; } else { response.ResponseCode = 0; response.ResponseMessage = "登录成功"; response.ResponseData = UserInfoDto.CreateFromUser(user); HttpContext.Session.SetString("CurrentUser", JsonConvert.SerializeObject(user)); } } catch (Exception e) { response.ResponseCode = -1; response.ResponseMessage = e.Message; } return(Json(response)); }
public ActionResult AddUser([FromBody] AddUserInfoDto userInfo) { var response = new ResponseDataHelper <UserInfoDto>(); try { //var user= var user = _userLogic.GetUserByLoginName(userInfo.LoginName); if (user == null) { user = _userLogic.AddUser(userInfo.ToUser()); response.ResponseData = UserInfoDto.CreateFromUser(user); } else { response.ResponseCode = -1; response.ResponseMessage = "登录名已存在"; } } catch (Exception e) { response.ResponseCode = -1; response.ResponseMessage = e.Message; } return(Json(response)); }
public ActionResult GetCurrentUser() { var response = new ResponseDataHelper <UserInfoDto>(); try { var userString = HttpContext.Session.GetString("CurrentUser"); if (!string.IsNullOrEmpty(userString)) { var user = JsonConvert.DeserializeObject <User>(userString); if (user != null) { UserInfoDto userInfo = UserInfoDto.CreateFromUser(user); response.ResponseData = userInfo; response.ResponseCode = 0; response.ResponseMessage = "获取用户信息成功"; } else { response.ResponseCode = -1001; response.ResponseMessage = "用户未登录"; } } else { response.ResponseCode = -1001; response.ResponseMessage = "用户未登录"; } //response.PagerData = new PagerHelper() //{ // DataCount = totalCount, // PageSize = pageSize //}; } catch (Exception e) { response.ResponseCode = -1; response.ResponseMessage = e.Message; } return(Json(response)); }
public ActionResult Get(int id) { var response = new ResponseDataHelper <UserInfoDto>(); try { //var user= User u = _userLogic.GetUserById(id); UserInfoDto userInfo = UserInfoDto.CreateFromUser(u); response.ResponseData = userInfo; //response.PagerData = new PagerHelper() //{ // DataCount = totalCount, // PageSize = pageSize //}; } catch (Exception e) { response.ResponseCode = -1; response.ResponseMessage = e.Message; } return(Json(response)); }