예제 #1
0
        public async Task <IActionResult> GetCustomers(
            [FromQuery] CustomerFilterQuery filterQuery,
            [FromQuery] PaginationQuery paginationQuery)
        {
            var pagination = _mapper.Map <PaginationParams>(paginationQuery);
            var filter     = _mapper.Map <CustomerFilterQuery, CustomerFilterParams>(filterQuery);

            var customers = (await _customerService.GetAllCustomersAsync(filter, pagination)).ToArray();

            var paginationResponse =
                PaginationHelpers.CreatePaginatedQueryResponse(_uriGeneratorService, pagination, customers, customers.Count());

            return(Ok(paginationResponse));
        }
예제 #2
0
        public async Task <IActionResult> GetAllOrders(
            [FromQuery] OrderFilterQuery filterQuery,
            [FromQuery] PaginationQuery paginationQuery)
        {
            int customerId = User.GetClaim <int>(ClaimTypes.NameIdentifier);

            var filter     = _mapper.Map <OrderFilterParams>(filterQuery);
            var pagination = _mapper.Map <PaginationParams>(paginationQuery);

            filter.CustomerId = customerId;

            var resultOrders = (await _orderService.GetAllOrdersAsync(filter, pagination)).ToArray();

            var paginationResponse =
                PaginationHelpers.CreatePaginatedQueryResponse(_uriGeneratorService, pagination, resultOrders, resultOrders.Count());

            return(Ok(paginationResponse));
        }
예제 #3
0
        public async Task <IActionResult> GetAll(
            [FromQuery] ProductFilterQuery filterQuery,
            [FromQuery] PaginationQuery paginationQuery)
        {
            var pagination = _mapper.Map <PaginationParams>(paginationQuery);
            var filter     = _mapper.Map <ProductFilterParams>(filterQuery);

            _productService.AttachOutputDevice(_outputDevice);

            var products = (await _productService.GetAllProductsAsync(filter, pagination)).ToArray();

            var queryResult = _outputDevice.GetFilteredProductCount();

            var paginationResponse =
                PaginationHelpers.CreatePaginatedQueryResponse(_uriGeneratorService, pagination, products, products.Length);

            paginationResponse.FetchedItems = queryResult.FilteredCount;
            paginationResponse.QueriedItems = queryResult.TotalCount;

            return(Ok(paginationResponse));
        }