Example #1
0
        public async Task <OrderAttributeGetPagedListResponse> GetPagedListAsync(
            Guid accountId,
            OrderAttributeGetPagedListRequest request,
            CancellationToken ct)
        {
            var attributes = _storage.OrderAttributes
                             .AsNoTracking()
                             .Where(x =>
                                    x.AccountId == accountId &&
                                    (request.Types == null || !request.Types.Any() || request.Types.Contains(x.Type)) &&
                                    (request.Key.IsEmpty() || EF.Functions.ILike(x.Key, $"{request.Key}%")) &&
                                    (!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 OrderAttributeGetPagedListResponse
            {
                TotalCount = await attributes
                             .CountAsync(ct),
                LastModifyDateTime = await attributes
                                     .MaxAsync(x => x != null?x.ModifyDateTime ?? x.CreateDateTime : (DateTime?)null, ct),
                Attributes = await attributes
                             .SortBy(request.SortBy, request.OrderBy)
                             .Skip(request.Offset)
                             .Take(request.Limit)
                             .ToListAsync(ct)
            });
        }
        public async Task WhenGetPagedList_ThenSuccess()
        {
            var headers = await _defaultRequestHeadersService.GetAsync();

            var key = "Test".WithGuid();
            await Task.WhenAll(
                _create.OrderAttribute
                .WithType(AttributeType.Text)
                .WithKey(key)
                .BuildAsync());

            var filterTypes = new List <AttributeType> {
                AttributeType.Text
            };

            var request = new OrderAttributeGetPagedListRequest
            {
                Key   = key,
                Types = filterTypes,
            };

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

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

            Assert.NotEmpty(response.Attributes);
            Assert.All(results, Assert.True);
        }
        public async Task <ActionResult <OrderAttributeGetPagedListResponse> > GetPagedList(
            OrderAttributeGetPagedListRequest request,
            CancellationToken ct = default)
        {
            var response = await _orderAttributesService.GetPagedListAsync(_userContext.AccountId, request, ct);

            return(ReturnIfAllowed(response, Roles.Orders, response.Attributes.Select(x => x.AccountId)));
        }
Example #4
0
 public Task <OrderAttributeGetPagedListResponse> GetPagedListAsync(
     OrderAttributeGetPagedListRequest request,
     Dictionary <string, string> headers = default,
     CancellationToken ct = default)
 {
     return(_factory.PostAsync <OrderAttributeGetPagedListResponse>(
                _host + "/Orders/Attributes/v1/GetPagedList", null, request, headers, ct));
 }