Skip to content

Commit 538a5c7

Browse files
addressing review comments
1 parent f04b47b commit 538a5c7

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

NorthwindCRUD/Services/PagingService.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public PagingService(IMapper mapper)
2323

2424
public PagedResultDto<TDto> GetPagedData<TEntity, TDto>(IEnumerable<TEntity> data, int? skip, int? top, string? orderBy)
2525
{
26-
var dataArray = data.ToArray();
27-
var totalRecords = dataArray.Length;
26+
var totalRecords = data.Count();
2827

2928
// Default skip and top if not provided
3029
int skipRecordsAmount = skip ?? 0;
@@ -33,11 +32,11 @@ public PagedResultDto<TDto> GetPagedData<TEntity, TDto>(IEnumerable<TEntity> dat
3332
// Apply ordering if specified
3433
if (!string.IsNullOrEmpty(orderBy))
3534
{
36-
dataArray = ApplyOrdering(dataArray.AsQueryable(), orderBy).ToArray();
35+
data = ApplyOrdering(data.AsQueryable(), orderBy).ToArray();
3736
}
3837

3938
// Apply pagination
40-
var pagedData = dataArray
39+
var pagedData = data
4140
.Skip(skipRecordsAmount)
4241
.Take(currentSize)
4342
.ToArray();
@@ -52,7 +51,7 @@ public PagedResultDto<TDto> GetPagedData<TEntity, TDto>(IEnumerable<TEntity> dat
5251
{
5352
Items = pagedDataDtos,
5453
TotalRecordsCount = totalRecords,
55-
PageSize = currentSize,
54+
PageSize = pagedDataDtos.Length,
5655
PageNumber = (skipRecordsAmount / currentSize) + 1,
5756
TotalPages = totalPages,
5857
};

0 commit comments

Comments
 (0)