Esempio n. 1
0
 public Task <StockArrivalChangeGetPagedListResponse> GetPagedListAsync(
     StockArrivalChangeGetPagedListRequest request,
     Dictionary <string, string> headers = default,
     CancellationToken ct = default)
 {
     return(_factory.PostAsync <StockArrivalChangeGetPagedListResponse>(
                _host + "/Stock/Arrivals/Changes/v1/GetPagedList", null, request, headers, ct));
 }
        public async Task <ActionResult <StockArrivalChangeGetPagedListResponse> > GetPagedList(
            StockArrivalChangeGetPagedListRequest request,
            CancellationToken ct = default)
        {
            var arrival = await _stockArrivalsService.GetAsync(request.StockArrivalId, false, ct);

            var response = await _stockArrivalChangesService.GetPagedListAsync(request, ct);

            return(ReturnIfAllowed(response, Roles.Stock, arrival.AccountId));
        }
        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();

            var arrival = await _create.StockArrival
                          .WithType(StockArrivalType.ArrivalFromSupplier)
                          .WithItem(room.Id, product.Id, 1)
                          .BuildAsync();

            arrival.IsDeleted = true;

            await _stockArrivalsClient.UpdateAsync(arrival, headers);

            var request = new StockArrivalChangeGetPagedListRequest
            {
                StockArrivalId = arrival.Id,
                SortBy         = "CreateDateTime",
                OrderBy        = "asc"
            };

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

            Assert.NotEmpty(response.Changes);
            Assert.True(response.Changes.All(x => !x.ChangerUserId.IsEmpty()));
            Assert.True(response.Changes.All(x => x.StockArrivalId == arrival.Id));
            Assert.True(response.Changes.All(x => x.CreateDateTime.IsMoreThanMinValue()));
            Assert.True(response.Changes.First().OldValueJson.IsEmpty());
            Assert.True(!response.Changes.First().NewValueJson.IsEmpty());
            Assert.NotNull(response.Changes.First().NewValueJson.FromJsonString <StockArrival>());
            Assert.True(!response.Changes.Last().OldValueJson.IsEmpty());
            Assert.True(!response.Changes.Last().NewValueJson.IsEmpty());
            Assert.False(response.Changes.Last().OldValueJson.FromJsonString <StockArrival>().IsDeleted);
            Assert.True(response.Changes.Last().NewValueJson.FromJsonString <StockArrival>().IsDeleted);
        }
Esempio n. 4
0
        public async Task <StockArrivalChangeGetPagedListResponse> GetPagedListAsync(
            StockArrivalChangeGetPagedListRequest request,
            CancellationToken ct)
        {
            var changes = _storage.StockArrivalChanges
                          .AsNoTracking()
                          .Where(x =>
                                 (request.StockArrivalId.IsEmpty() || x.StockArrivalId == request.StockArrivalId) &&
                                 (!request.MinCreateDate.HasValue || x.CreateDateTime >= request.MinCreateDate) &&
                                 (!request.MaxCreateDate.HasValue || x.CreateDateTime <= request.MaxCreateDate));

            return(new StockArrivalChangeGetPagedListResponse
            {
                TotalCount = await changes
                             .CountAsync(ct),
                Changes = await changes
                          .SortBy(request.SortBy, request.OrderBy)
                          .Skip(request.Offset)
                          .Take(request.Limit)
                          .ToListAsync(ct)
            });
        }