public async Task <GetPages.Response> GetPages(GetPages.Request request, CancellationToken cancellationToken) { var total = await _repository.Count(cancellationToken); if (total == 0) { return(new GetPages.Response { Total = 0, Offset = request.Offset, Limit = request.Limit }); } var isCategorySet = request.CategoryId != 0; List <int> categoryIds = null; PagedList <Domain.Advertisement> ads; if (isCategorySet) { categoryIds = await _categoryRepository.FindCategoryIdsByParent(request.CategoryId, cancellationToken); } ads = await _repository.GetPageByFilterSortSearch(request, categoryIds, cancellationToken); return(new GetPages.Response { Items = ads.Select(a => new Item { Id = a.Id, Title = a.Title, Description = a.Description, Cover = a.Cover, Price = a.Price, CreatedDate = a.CreatedDate, Status = a.Status.ToString(), Location = a.Location, Owner = new OwnerResponse { Id = a.OwnerId, Username = a.OwnerUser.Username, Email = a.OwnerUser.Email, Name = a.OwnerUser.Name, Lastname = a.OwnerUser.LastName, Avatar = a.OwnerUser.Avatar }, Category = new GetPages.Response.CategoryResponse { Id = a.Category.Id, Name = a.Category.Name }, Images = a.Images.Select(i => new ImageResponse { Id = i.Id, ImageUrl = S3Url + i.Name }), }), Total = ads.Total, Offset = request.Offset, Limit = request.Limit, }); }