public async Task <UserListResponse> getUsersAsync(ListDTO listDTO) { try { UserListResponse userListResponse = new UserListResponse(); userListResponse.Users = new List <UserRow>(); var lst = Context.Users.Select(a => new UserRow { Id = a.Id, UserName = a.UserName, Email = a.Email }).AsQueryable(); if (listDTO.Filter != null && listDTO.Filter != string.Empty) { lst = new LinqSearch().ApplyFilter(lst, listDTO.Filter); } userListResponse.LstCount = await lst.CountAsync(); userListResponse.Users = await lst.Skip((listDTO.PageNum - 1) *listDTO.PageSize).Take(listDTO.PageSize).ToListAsync(); userListResponse.ToSuccess <UserListResponse>(); return(userListResponse); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <UserListResponse> Login([FromBody] UserLoginRequest user) { UserListResponse userListResponse = new UserListResponse(); if (ModelState.IsValid) { userListResponse.Users = new List <UserRow>(); UserRow userRow = new UserRow(); var existingUser = await _userManager.FindByNameAsync(user.UserName); if (existingUser == null) { return(userListResponse.ToInvalidUserNameOrPassword <UserListResponse>()); } var isCorrect = await _userManager.CheckPasswordAsync(existingUser, user.Password); if (isCorrect) { Constants.LoginUserName = user.UserName; var jwtToken = GenerateJwtToken(existingUser.Id); userRow.Token = jwtToken; } else { return(userListResponse.ToInvalidUserNameOrPassword <UserListResponse>()); } var roles = _aspNetUserRolesService.getUserRolesByUserIdAsync(existingUser.Id); if (roles != null) { userRow.Roles = new List <RoleRow>(); userRow.Roles = roles.Result.Roles; } var claim = _aspNetUserRolesService.getUserClaimsByUserIdAsync(existingUser.Id); if (claim != null) { userRow.Claims = new List <ClaimsRow>(); userRow.Claims = claim.Result.Claims; } userRow.UserName = user.UserName; userRow.Id = existingUser.Id; userRow.Email = existingUser.Email; userListResponse.Users.Add(userRow); userListResponse.ToSuccess <UserListResponse>(); return(userListResponse); } return(userListResponse.ToIncompleteInput <UserListResponse>()); }