public IActionResult GetUsers(int page = 0, int pageSize = standardPageSize) { var totalUsers = _dataService.userAmount(); var totalPages = GetTotalPages(pageSize, totalUsers); if (page > totalPages - 1) { page = 0; } var users = _dataService.getUser(page, pageSize); if (users == null) { return(NotFound()); } var result = new { Total = totalUsers, Pages = totalPages, Page = page, Prev = Link(nameof(GetUsers), page, pageSize, -1, () => page > 0), Next = Link(nameof(GetUsers), page, pageSize, 1, () => page < totalPages - 1), Url = Link(nameof(GetUsers), page, pageSize), Data = users }; return(Ok(result)); }
public IActionResult GetUsers(int page = 0, int pageSize = standardPageSize) { var totalUsers = _dataService.userAmount(); var totalPages = GetTotalPages(pageSize, totalUsers); if (page > totalPages - 1) { page = 0; } var users = _dataService.getUser(page, pageSize) .Select(x => new { Link = Url.Link("GetSpecificUser", new { id = x.id }), Body = x.age, x.name, x.location, x.creationDate }); if (users == null) { return(NotFound()); } var result = new { Total = totalUsers, Pages = totalPages, Page = page, Prev = Link(nameof(GetUsers), page, pageSize, -1, () => page > 0), Next = Link(nameof(GetUsers), page, pageSize, 1, () => page < totalPages - 1), Url = Link(nameof(GetUsers), page, pageSize), Data = users }; return(Ok(result)); }