public async Task <ProductCategoryGetPagedListResponse> GetPagedListAsync(
            Guid accountId,
            ProductCategoryGetPagedListRequest request,
            CancellationToken ct)
        {
            var categories = _storage.ProductCategories
                             .AsNoTracking()
                             .Where(x =>
                                    x.AccountId == accountId &&
                                    (request.Name.IsEmpty() || EF.Functions.ILike(x.Name, $"{request.Name}%")) &&
                                    (!request.IsDeleted.HasValue || x.IsDeleted == request.IsDeleted) &&
                                    (!request.MinCreateDate.HasValue || x.CreateDateTime >= request.MinCreateDate) &&
                                    (!request.MaxCreateDate.HasValue || x.CreateDateTime <= request.MaxCreateDate) &&
                                    (!request.MinModifyDate.HasValue || x.ModifyDateTime >= request.MinModifyDate) &&
                                    (!request.MaxModifyDate.HasValue || x.ModifyDateTime <= request.MaxModifyDate));

            return(new ProductCategoryGetPagedListResponse
            {
                TotalCount = await categories
                             .CountAsync(ct),
                LastModifyDateTime = await categories
                                     .MaxAsync(x => x != null?x.ModifyDateTime ?? x.CreateDateTime : (DateTime?)null, ct),
                Categories = await categories
                             .SortBy(request.SortBy, request.OrderBy)
                             .Skip(request.Offset)
                             .Take(request.Limit)
                             .ToListAsync(ct)
            });
        }
 public Task <ProductCategoryGetPagedListResponse> GetPagedListAsync(
     ProductCategoryGetPagedListRequest request,
     Dictionary <string, string> headers = default,
     CancellationToken ct = default)
 {
     return(_factory.PostAsync <ProductCategoryGetPagedListResponse>(
                _host + "/Products/Categories/v1/GetPagedList", null, request, headers, ct));
 }
        public async Task <ActionResult <ProductCategoryGetPagedListResponse> > GetPagedList(
            ProductCategoryGetPagedListRequest request,
            CancellationToken ct = default)
        {
            var response = await _userCategoriesService.GetPagedListAsync(_userContext.AccountId, request, ct);

            return(ReturnIfAllowed(
                       response,
                       Roles.Products,
                       response.Categories.Select(x => x.AccountId)));
        }
        public async Task WhenGetPagedList_ThenSuccess()
        {
            var headers = await _defaultRequestHeadersService.GetAsync();

            var name = "Test".WithGuid();
            await Task.WhenAll(_create.ProductCategory
                               .WithName(name)
                               .BuildAsync());

            var request = new ProductCategoryGetPagedListRequest
            {
                Name = name
            };

            var response = await _productCategoriesClient.GetPagedListAsync(request, headers);

            var results = response.Categories
                          .Skip(1)
                          .Zip(response.Categories, (previous, current) => current.CreateDateTime >= previous.CreateDateTime);

            Assert.NotEmpty(response.Categories);
            Assert.All(results, Assert.True);
        }