public async Task <IActionResult> GetSamples([FromQuery] SampleParametersDto sampleParametersDto)
        {
            // add error handling
            var query         = new SampleListQuery(sampleParametersDto);
            var queryResponse = await _mediator.Send(query);

            var paginationMetadata = new
            {
                totalCount        = queryResponse.TotalCount,
                pageSize          = queryResponse.PageSize,
                currentPageSize   = queryResponse.CurrentPageSize,
                currentStartIndex = queryResponse.CurrentStartIndex,
                currentEndIndex   = queryResponse.CurrentEndIndex,
                pageNumber        = queryResponse.PageNumber,
                totalPages        = queryResponse.TotalPages,
                hasPrevious       = queryResponse.HasPrevious,
                hasNext           = queryResponse.HasNext
            };

            Response.Headers.Add("X-Pagination",
                                 JsonSerializer.Serialize(paginationMetadata));

            var response = new Response <IEnumerable <SampleDto> >(queryResponse);

            return(Ok(response));
        }
        public async Task <IActionResult> GetSamples([FromQuery] SampleParametersDto sampleParametersDto, CancellationToken cancellationToken)
        {
            var samplesFromRepo = await _sampleRepository.GetSamplesAsync(sampleParametersDto, cancellationToken);

            var paginationMetadata = new
            {
                totalCount        = samplesFromRepo.TotalCount,
                pageSize          = samplesFromRepo.PageSize,
                currentPageSize   = samplesFromRepo.CurrentPageSize,
                currentStartIndex = samplesFromRepo.CurrentStartIndex,
                currentEndIndex   = samplesFromRepo.CurrentEndIndex,
                pageNumber        = samplesFromRepo.PageNumber,
                totalPages        = samplesFromRepo.TotalPages,
                hasPrevious       = samplesFromRepo.HasPrevious,
                hasNext           = samplesFromRepo.HasNext
            };

            Response.Headers.Add("X-Pagination",
                                 JsonSerializer.Serialize(paginationMetadata));

            var samplesDto = _mapper.Map <IEnumerable <SampleDto> >(samplesFromRepo);
            var response   = new Response <IEnumerable <SampleDto> >(samplesDto);

            return(Ok(response));
        }
        public async Task <PagedList <Sample> > GetSamplesAsync(SampleParametersDto sampleParameters, CancellationToken cancellationToken)
        {
            if (sampleParameters == null)
            {
                throw new ArgumentNullException(nameof(sampleParameters));
            }

            var collection = _context.Samples
                             as IQueryable <Sample>; // TODO: AsNoTracking() should increase performance, but will break the sort tests. need to investigate

            var sieveModel = new SieveModel
            {
                Sorts   = sampleParameters.SortOrder ?? "SampleId",
                Filters = sampleParameters.Filters
            };

            collection = _sieveProcessor.Apply(sieveModel, collection);

            return(await PagedList <Sample> .CreateAsync(collection,
                                                         sampleParameters.PageNumber,
                                                         sampleParameters.PageSize,
                                                         cancellationToken));
        }
 public SampleListQuery(SampleParametersDto queryParameters)
 {
     QueryParameters = queryParameters;
 }