Answer the question
In order to leave comments, you need to log in
How can you shorten the code?
public async Task<IList<WishlistItemDto>> GetAllAsync(PageInfo pageInfo)
{
if (pageInfo.Page <= 0 || pageInfo.ItemsPerPage <= 0)
{
pageInfo.Page = 1;
pageInfo.ItemsPerPage = 1;
}
int pageSize = 10;
int pageNumber = (pageInfo.Page - 1) * pageInfo.ItemsPerPage;
var items = await _wishListItemRepository.GetAllAsync(pageNumber, pageSize);
var reversedList = (List<WishlistItemDto>)_mapper.Map<IList<WishlistItemDto>>(items);
reversedList.Reverse();
return reversedList;
}
Answer the question
In order to leave comments, you need to log in
It will not work to shorten the code, because it is already very compact
Page number and page size in PageInfo, it makes sense to control it from the outside, for example, in the constructor or the PageInfo
Offset and Limit properties, it makes sense to take it out - to extensions or to PageInfo methods
public async Task<IList<WishlistItemDto>> GetAllAsync(PageInfo pageInfo)
{
var items = await _wishListItemRepository.GetAllAsync(pageInfo.Offset(), pageInfo.Limit());
return _mapper.Map<IList<WishlistItemDto>>(items).Reverse().ToList();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question