public IActionResult NewUserOrg(int id, string uid) { var usrids = uid.Split(','); foreach (var idstr in usrids) { sys_user sysUser = _sysUserRpt.GetSingle(int.Parse(idstr)); if (sysUser != null) { sysUser.OrgId = id; } } _sysUserRpt.Commit(); return(new NoContentResult()); }
public async Task <IActionResult> Post([FromBody] sys_user value) { using (var tran = _context.Database.BeginTransaction()) { try { var oldSysUser = _sysUserRpt.FindBy(f => f.UserId == value.UserId); if (oldSysUser.Any()) { return(BadRequest(string.Concat(value.UserId, "已经存在。"))); } value.CreatedAt = DateTime.Now; value.UpdatedAt = DateTime.Now; value.IsDelete = false; if (User.Identity is ClaimsIdentity identity) { value.CreatedBy = identity.Name ?? "admin"; } _sysUserRpt.Add(value); _sysUserRpt.Commit(); if (!string.IsNullOrEmpty(value.RoleIds) && value.RoleIds.Length > 1) { //新增用户角色关系表 string[] roles = value.RoleIds.Split(",".ToArray()); foreach (var item in roles) { if (!string.IsNullOrEmpty(item)) { var userrole = new sys_role_user { RoleId = int.Parse(item), UserId = value.Id }; _sysRoleUserRpt.Add(userrole); } } _sysRoleUserRpt.Commit(); } tran.Commit(); } catch (Exception ex) { Console.WriteLine(ex); tran.Rollback(); return(BadRequest(ex)); } } return(new OkObjectResult(value)); }
public IActionResult Login([FromBody] sys_user user) { //User existUser = UserStorage.Users.FirstOrDefault(u => u.Username == user.Username && u.Password == user.Password); var existUser = _sysUserRpt.GetSingle(f => f.UserId == user.UserId && f.Pwd == user.Pwd); if (existUser != null) { existUser.LastLoginTime = DateTime.Now; _sysUserRpt.Commit(); var requestAt = DateTime.Now; var expiresIn = requestAt + TokenAuthOption.ExpiresSpan; var token = GenerateToken(existUser, expiresIn); return(Json(new RequestResult { State = RequestState.Success, Data = new { requertAt = requestAt, expiresIn = TokenAuthOption.ExpiresSpan.TotalSeconds, tokeyType = TokenAuthOption.TokenType, accessToken = token } })); } return(Json(new RequestResult { State = RequestState.Failed, Msg = "Óû§Ãû»òÃÜÂë´íÎó¡£" })); }