コード例 #1
0
ファイル: AccountController.cs プロジェクト: dadagov125/PWApp
        public async Task <IActionResult> Users([FromQuery] UsersListFilter filter)
        {
            filter.IgnoreUserId = UserManager.GetUserId(User);

            var users = await AccountService.GetUsersList(filter);

            return(Json(users));
        }
コード例 #2
0
        public async Task <UsersListResponse> GetUsersList(UsersListFilter filter)
        {
            UsersListResponse result = new UsersListResponse();

            var query = Context.Users.AsQueryable();

            if (!string.IsNullOrWhiteSpace(filter?.IgnoreUserId))
            {
                query = query.Where(u => u.Id != filter.IgnoreUserId);
            }

            if (!string.IsNullOrWhiteSpace(filter?.Text))
            {
                var text = filter.Text;
                query = query.Where(u =>
                                    u.FirstName.Contains(text) ||
                                    u.LastName.Contains(text) ||
                                    u.UserName.Contains(text) ||
                                    u.Email.Contains(text) ||
                                    u.PhoneNumber.Contains(text));
            }

            result.TotalCount = await query.CountAsync();

            if (filter != null)
            {
                if (filter.Skip.HasValue)
                {
                    var skip = filter.Skip.Value;
                    query          = query.Skip(skip);
                    result.Skipped = result.TotalCount > 0 ? skip : 0;
                }

                if (filter.Take.HasValue)
                {
                    var take = filter.Take.Value;
                    query        = query.Take(take);
                    result.Taken = result.TotalCount > 0 ? take : 0;
                }
            }

            result.List = await query.Select(u => UserResponse.FromUser(u)).ToListAsync();

            return(result);
        }