-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from marcominerva/develop
Add PaginatedListResult class
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,4 +118,4 @@ | |
.Produces(StatusCodes.Status404NotFound) | ||
.WithOpenApi(); | ||
|
||
app.Run(); | ||
app.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace OperationResults; | ||
|
||
public class PaginatedListResult<T> | ||
{ | ||
public IEnumerable<T>? Items { get; set; } | ||
|
||
public int PageIndex { get; set; } | ||
|
||
public int PageSize { get; set; } | ||
|
||
public int TotalCount { get; set; } | ||
|
||
public bool HasNextPage { get; set; } | ||
|
||
public PaginatedListResult() | ||
{ | ||
} | ||
|
||
public PaginatedListResult(IEnumerable<T>? items, int totalCount, int pageIndex, int pageSize = 0) | ||
{ | ||
Items = items; | ||
TotalCount = totalCount; | ||
PageIndex = pageIndex; | ||
PageSize = pageSize > 0 ? pageSize : items?.Count() ?? 0; | ||
HasNextPage = totalCount > (pageIndex * PageSize) + (items?.Count() ?? 0); | ||
} | ||
|
||
public PaginatedListResult(IEnumerable<T>? items, bool hasNextPage = false) : this(items, items?.Count() ?? 0, hasNextPage) | ||
{ | ||
} | ||
|
||
public PaginatedListResult(IEnumerable<T>? items, int totalCount, bool hasNextPage = false) | ||
{ | ||
Items = items; | ||
TotalCount = totalCount; | ||
PageIndex = 0; | ||
PageSize = items?.Count() ?? 0; | ||
HasNextPage = items?.Count() != totalCount && hasNextPage; | ||
} | ||
} |