示例#1
0
        public async Task <ActionResult <CollectionWithPaginationData <UserDto> > > GetOnlineFriends(string userId, [FromQuery] PaginationParams paginationParams)
        {
            if (Guid.TryParse(userId, out Guid gUserId))
            {
                try
                {
                    paginationParams.Skip = (paginationParams.PageNumber - 1) * paginationParams.PageSize;
                    if (await _userService.CheckIfUserExists(gUserId))
                    {
                        PagedList <UserDto> usersToReturn = await _onlineUsersService.GetOnlineFriends(gUserId, paginationParams);

                        return(Ok(this.CreateCollectionWithPagination(usersToReturn, paginationParams, "GetOnlineFriends")));
                    }
                    else
                    {
                        return(NotFound($"User: {userId} not found."));
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Error occured during getting the online friends. User id: {user}", userId);
                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }
            }
            else
            {
                return(BadRequest($"{userId} is not valid guid."));
            }
        }