Exemplo n.º 1
0
        public async Task <StockArrivalGetPagedListResponse> GetPagedListAsync(
            Guid accountId,
            StockArrivalGetPagedListRequest request,
            CancellationToken ct)
        {
            var arrivals = await _storage.StockArrivals
                           .AsNoTracking()
                           .Include(x => x.Items)
                           .ThenInclude(x => x.Room)
                           .Where(x => x.AccountId == accountId &&
                                  (!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 StockArrivalGetPagedListResponse
            {
                TotalCount = arrivals
                             .Count(x => x.FilterByAdditional(request)),
                LastModifyDateTime = arrivals
                                     .Max(x => x.ModifyDateTime),
                Arrivals = arrivals
                           .Where(x => x.FilterByAdditional(request))
                           .AsQueryable()
                           .SortBy(request.SortBy, request.OrderBy)
                           .Skip(request.Offset)
                           .Take(request.Limit)
                           .ToList()
            });
        }
Exemplo n.º 2
0
        public async Task WhenGetPagedList_ThenSuccess()
        {
            var headers = await _defaultRequestHeadersService.GetAsync();

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

            var room = await _create.StockRoom
                       .BuildAsync();

            var product = await _create.Product
                          .WithStatusId(productStatus.Id)
                          .BuildAsync();

            await Task.WhenAll(
                _create.StockArrival
                .WithType(StockArrivalType.ArrivalFromSupplier)
                .WithItem(room.Id, product.Id, 1)
                .BuildAsync(),
                _create.StockArrival
                .WithType(StockArrivalType.ArrivalFromSupplier)
                .WithItem(room.Id, product.Id, 1)
                .BuildAsync());

            var request = new StockArrivalGetPagedListRequest();

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

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

            Assert.NotEmpty(response.Arrivals);
            Assert.All(results, Assert.True);
        }
Exemplo n.º 3
0
 public Task <StockArrivalGetPagedListResponse> GetPagedListAsync(
     StockArrivalGetPagedListRequest request,
     Dictionary <string, string> headers = default,
     CancellationToken ct = default)
 {
     return(_factory.PostAsync <StockArrivalGetPagedListResponse>(
                _host + "/Stock/Arrivals/v1/GetPagedList", null, request, headers, ct));
 }
Exemplo n.º 4
0
        public async Task <ActionResult <StockArrivalGetPagedListResponse> > GetPagedList(
            StockArrivalGetPagedListRequest request,
            CancellationToken ct = default)
        {
            var response = await _stockArrivalsService.GetPagedListAsync(_userContext.AccountId, request, ct);

            return(ReturnIfAllowed(response, Roles.Stock, response.Arrivals.Select(x => x.AccountId)));
        }
Exemplo n.º 5
0
 public static bool FilterByAdditional(this StockArrival arrival, StockArrivalGetPagedListRequest request)
 {
     return((request.Types == null || !request.Types.Any() ||
             request.Types.Any(x => TypesPredicate(arrival, x))) &&
            (request.CreateUserIds == null || !request.CreateUserIds.Any() ||
             request.CreateUserIds.Any(x => CreateUserIdsPredicate(arrival, x))) &&
            (request.SupplierIds == null || !request.SupplierIds.Any() ||
             request.SupplierIds.Any(x => SupplierIdsPredicate(arrival, x))) &&
            (request.OrderIds == null || !request.OrderIds.Any() ||
             request.OrderIds.Any(x => OrderIdsPredicate(arrival, x))) &&
            (request.InventoryIds == null || !request.InventoryIds.Any() ||
             request.InventoryIds.Any(x => InventoryIdsPredicate(arrival, x))) &&
            (request.ItemsRoomIds == null || !request.ItemsRoomIds.Any() ||
             request.ItemsRoomIds.Any(x => ItemsRoomIdsPredicate(arrival, x))) &&
            (request.ItemsProductIds == null || !request.ItemsProductIds.Any() ||
             request.ItemsProductIds.Any(x => ItemsProductIdsPredicate(arrival, x))));
 }