public async Task <ActionResult <GetByIdAuctionResponse> > GetById([FromRoute] GetByIdAuctionRequest request, CancellationToken cancellationToken) { _logger.LogInformation($"Call /api/Auction/{request.AuctionId}"); var includeSpec = new AuctionIncludeSpecification(request.AuctionId); var auctions = await _auctionRepository.ListAsync(includeSpec, cancellationToken); if (auctions == null) { return(NotFound()); } var response = new GetByIdAuctionResponse(request.CorrelationId()) { Auction = Mapper.Map <Auction, AuctionDto>(auctions.First()) }; return(Ok(response)); }
public async Task <ActionResult <ListPagedAuctionResponse> > ListPaged([FromQuery] ListPagedAuctionRequest request, CancellationToken cancellationToken) { _logger.LogInformation("Call /api/Auction"); // var category = request.CategoryId.HasValue // ? await _categoryRepository.GetByIdAsync(request.CategoryId.Value, cancellationToken) // : null; // var filterSpec = new AuctionFilterSpecification(request.CategoryId); // var totalItems = await _auctionRepository.CountAsync(filterSpec, cancellationToken); var includeSpec = new AuctionIncludeSpecification(); var auctions = await _auctionRepository.ListAsync(includeSpec, cancellationToken); auctions = _auctionService.FilterAuctions(auctions, request.Title, request.StartTime, request.EndTime, request.CategoryId); var totalItems = auctions.Count; auctions = auctions .Skip((request.PageIndex - 1) * request.PageSize) .Take(request.PageSize) .ToList(); // var specPaged = new AuctionFilterPaginatedSpecification( // (request.PageIndex-1) * request.PageSize, // request.PageSize // ); // var auctions = await _auctionRepository.ListAsync(specPaged, cancellationToken); var response = new ListPagedAuctionResponse(request.CorrelationId()) { PageSize = request.PageSize, PageCount = int.Parse(Math.Ceiling((decimal)totalItems / request.PageSize).ToString()), PageIndex = request.PageIndex, Auctions = auctions.Select(a => Mapper.Map <Auction, AuctionDto>(a)).ToList(), ResponseItemsCount = totalItems }; return(Ok(response)); }