public async Task <IActionResult> GetPageOfListItems([FromQuery] CustomersParameters customerParameters) { var customers = await _repository.Customer.GetPageOfListItems(customerParameters); Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(customers.MetaData)); return(Ok(customers)); }
public async Task <ActionResult <IEnumerable <CustomerGetViewModel> > > GetPage( [FromQuery] CustomersParameters customerParameters) { var pagedList = await repository.ListAsync(customerParameters); var metaData = pagedList.GetMetaData(); AddHeaders("GetCustomers", pagedList, customerParameters); return(Ok(mapper.Map <IEnumerable <CustomerGetViewModel> >(pagedList))); }
public async Task CustomerList_ShouldReturn_PagedList() { int count = 5; var mockLogger = new Mock <ILogger <CustomersController> >(); var mockRepository = new Mock <ICustomerRepository>(); mockRepository.Setup(repo => repo.ListAsync(new CustomersParameters())) .ReturnsAsync(await GetTestCustomerList(count)); var controller = new CustomersController(mockLogger.Object, mapper, mockRepository.Object); var customerParams = new CustomersParameters { PageNumber = 2, PageSize = 2 }; // Act var result = await controller.GetPage(customerParams); // Assert var apiResult = Assert.IsType <OkObjectResult>(result.Result); var model = Assert.IsAssignableFrom <IEnumerable <CustomerGetViewModel> >(apiResult.Value); Assert.Equal(customerParams.PageSize, model.Count()); }
public async Task OnGet(CustomersParameters parameters) { CustomerList = await repository.ListAsync(parameters); logger.LogInformation($"CustomerList count={CustomerList.Count()}"); }
public async Task <PagedList <CustomerListItem> > GetPageOfListItems(CustomersParameters customerParameters) { var customers = await this.GetAllListItems(); return(PagedList <CustomerListItem> .ToPagedList(customers, customerParameters.PageNumber, customerParameters.PageSize)); }