public Task <ProductGetPagedListResponse> GetPagedListAsync(
     ProductGetPagedListRequest request,
     Dictionary <string, string> headers = default,
     CancellationToken ct = default)
 {
     return(_factory.PostAsync <ProductGetPagedListResponse>(
                _host + "/Products/v1/GetPagedList", null, request, headers, ct));
 }
Beispiel #2
0
        public async Task <ActionResult <ProductGetPagedListResponse> > GetPagedList(
            ProductGetPagedListRequest request,
            CancellationToken ct = default)
        {
            var response = await _productsService.GetPagedListAsync(_userContext.AccountId, request, ct);

            return(ReturnIfAllowed(
                       response,
                       Roles.Products,
                       response.Products.Select(x => x.AccountId)));
        }
Beispiel #3
0
 public static bool FilterByAdditional(this Product product, ProductGetPagedListRequest request)
 {
     return((request.Types == null || !request.Types.Any() ||
             request.Types.Any(x => TypePredicate(product, x))) &&
            (request.StatusIds == null || !request.StatusIds.Any() ||
             request.StatusIds.Any(x => StatusIdsPredicate(product, x))) &&
            (request.Attributes == null || !request.Attributes.Any() ||
             (request.AllAttributes is false
                 ? request.Attributes.Any(x => AttributePredicate(product, x))
                 : request.Attributes.All(x => AttributePredicate(product, x)))) &&
            (request.CategoryIds == null || !request.CategoryIds.Any() ||
             (request.AllCategoryIds is false
                 ? request.CategoryIds.Any(x => CategoryPredicate(product, x))
                 : request.CategoryIds.All(x => CategoryPredicate(product, x)))));
 }
Beispiel #4
0
        public async Task WhenGetPagedList_ThenSuccess()
        {
            var headers = await _defaultRequestHeadersService.GetAsync();

            var attribute = await _create.ProductAttribute.BuildAsync();

            var category = await _create.ProductCategory.BuildAsync();

            var status = await _create.ProductStatus.BuildAsync();

            var value = "Test".WithGuid();
            await Task.WhenAll(
                _create.Product
                .WithStatusId(status.Id)
                .WithName("Test".WithGuid())
                .WithAttributeLink(attribute.Id, value)
                .WithCategoryLink(category.Id)
                .BuildAsync(),
                _create.Product
                .WithStatusId(status.Id)
                .WithName("Test".WithGuid())
                .WithAttributeLink(attribute.Id, value)
                .WithCategoryLink(category.Id)
                .BuildAsync());

            var filterAttributes = new Dictionary <Guid, string> {
                { attribute.Id, value }
            };
            var filterCategoryIds = new List <Guid> {
                category.Id
            };

            var request = new ProductGetPagedListRequest
            {
                Attributes  = filterAttributes,
                CategoryIds = filterCategoryIds
            };

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

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

            Assert.NotEmpty(response.Products);
            Assert.All(results, Assert.True);
        }
Beispiel #5
0
        public async Task <ProductGetPagedListResponse> GetPagedListAsync(
            Guid accountId,
            ProductGetPagedListRequest request,
            CancellationToken ct)
        {
            var products = await _storage.Products
                           .AsNoTracking()
                           .Include(x => x.Status)
                           .Include(x => x.AttributeLinks)
                           .Include(x => x.CategoryLinks)
                           .Where(x =>
                                  x.AccountId == accountId &&
                                  (request.ParentProductId.IsEmpty() || x.ParentProductId == request.ParentProductId) &&
                                  (request.Name.IsEmpty() || EF.Functions.ILike(x.Name, $"{request.Name}%")) &&
                                  (request.VendorCode.IsEmpty() || x.VendorCode == request.VendorCode) &&
                                  (request.MinPrice.IsEmpty() || x.Price >= request.MinPrice.Value) &&
                                  (request.MaxPrice.IsEmpty() || x.Price <= request.MaxPrice) &&
                                  (!request.IsHidden.HasValue || x.IsHidden == request.IsHidden) &&
                                  (!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))
                           .ToListAsync(ct);

            return(new ProductGetPagedListResponse
            {
                TotalCount = products
                             .Count(x => x.FilterByAdditional(request)),
                LastModifyDateTime = products
                                     .Max(x => x.ModifyDateTime),
                Products = products
                           .Where(x => x.FilterByAdditional(request))
                           .AsQueryable()
                           .SortBy(request.SortBy, request.OrderBy)
                           .Skip(request.Offset)
                           .Take(request.Limit)
                           .ToList()
            });
        }