Skip to content

Commit f657d8d

Browse files
authored
Merge pull request #32 from IgniteUI/add-remote-paging-capabilities
Add remote paging capabilities
2 parents f9da89b + 538a5c7 commit f657d8d

File tree

12 files changed

+389
-9
lines changed

12 files changed

+389
-9
lines changed

NorthwindCRUD/Controllers/CategoriesController.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ public class CategoriesController : ControllerBase
1313
{
1414
private readonly CategoryService categoryService;
1515
private readonly ProductService productService;
16+
private readonly PagingService pagingService;
1617
private readonly IMapper mapper;
1718
private readonly ILogger<CategoriesController> logger;
1819

19-
public CategoriesController(CategoryService categoryService, ProductService productService, IMapper mapper, ILogger<CategoriesController> logger)
20+
public CategoriesController(CategoryService categoryService, ProductService productService, PagingService pagingService, IMapper mapper, ILogger<CategoriesController> logger)
2021
{
2122
this.categoryService = categoryService;
2223
this.productService = productService;
24+
this.pagingService = pagingService;
2325
this.mapper = mapper;
2426
this.logger = logger;
2527
}
@@ -39,6 +41,33 @@ public ActionResult<CategoryDto[]> GetAll()
3941
}
4042
}
4143

44+
/// <summary>
45+
/// Fetches all categories or a page of categories based on the provided parameters.
46+
/// </summary>
47+
/// <param name="skip">The number of records to skip before starting to fetch the categories. If this parameter is not provided, fetching starts from the beginning.</param>
48+
/// <param name="top">The maximum number of categories to fetch. If this parameter is not provided, all categories are fetched.</param>
49+
/// <param name="orderBy">A comma-separated list of fields to order the categories by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
50+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
51+
[HttpGet("GetPagedCategories")]
52+
public ActionResult<PagedResultDto<ProductDto>> GetPagedCategories(int? skip, int? top, string? orderBy)
53+
{
54+
try
55+
{
56+
// Retrieve all categories
57+
var categories = this.categoryService.GetAll();
58+
59+
// Get paged data
60+
var pagedResult = pagingService.GetPagedData<CategoryDb, CategoryDto>(categories, skip, top, orderBy);
61+
62+
return Ok(pagedResult);
63+
}
64+
catch (Exception error)
65+
{
66+
logger.LogError(error.Message);
67+
return StatusCode(500);
68+
}
69+
}
70+
4271
[HttpGet("{id}")]
4372
public ActionResult<CategoryDto> GetById(int id)
4473
{

NorthwindCRUD/Controllers/CustomersController.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ public class CustomersController : Controller
1313
{
1414
private readonly CustomerService customerService;
1515
private readonly OrderService orderService;
16+
private readonly PagingService pagingService;
1617
private readonly IMapper mapper;
1718
private readonly ILogger<CustomersController> logger;
1819

19-
public CustomersController(CustomerService customerService, OrderService orderService, IMapper mapper, ILogger<CustomersController> logger)
20+
public CustomersController(CustomerService customerService, OrderService orderService, PagingService pagingService, IMapper mapper, ILogger<CustomersController> logger)
2021
{
2122
this.customerService = customerService;
2223
this.orderService = orderService;
24+
this.pagingService = pagingService;
2325
this.mapper = mapper;
2426
this.logger = logger;
2527
}
@@ -39,6 +41,33 @@ public ActionResult<CustomerDto[]> GetAll()
3941
}
4042
}
4143

44+
/// <summary>
45+
/// Fetches all customers or a page of customers based on the provided parameters.
46+
/// </summary>
47+
/// <param name="skip">The number of records to skip before starting to fetch the customers. If this parameter is not provided, fetching starts from the beginning.</param>
48+
/// <param name="top">The maximum number of customers to fetch. If this parameter is not provided, all customers are fetched.</param>
49+
/// <param name="orderBy">A comma-separated list of fields to order the customers by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
50+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
51+
[HttpGet("GetPagedCustomers")]
52+
public ActionResult<PagedResultDto<CustomerDto>> GetAllCustomers(int? skip, int? top, string? orderBy)
53+
{
54+
try
55+
{
56+
// Retrieve all customers
57+
var customers = this.customerService.GetAll();
58+
59+
// Get paged data
60+
var pagedResult = pagingService.GetPagedData<CustomerDb, CustomerDto>(customers, skip, top, orderBy);
61+
62+
return Ok(pagedResult);
63+
}
64+
catch (Exception error)
65+
{
66+
logger.LogError(error.Message);
67+
return StatusCode(500);
68+
}
69+
}
70+
4271
[HttpGet("{id}")]
4372
public ActionResult<CustomerDto> GetById(string id)
4473
{

NorthwindCRUD/Controllers/EmployeesController.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public class EmployeesController : Controller
1414
private readonly EmployeeService employeeService;
1515
private readonly EmployeeTerritoryService employeeTerritoryService;
1616
private readonly OrderService ordersService;
17+
private readonly PagingService pagingService;
1718
private readonly IMapper mapper;
1819
private readonly ILogger<EmployeesController> logger;
1920

20-
public EmployeesController(EmployeeService employeeService, EmployeeTerritoryService employeeTerritoryService, OrderService ordersService, IMapper mapper, ILogger<EmployeesController> logger)
21+
public EmployeesController(EmployeeService employeeService, EmployeeTerritoryService employeeTerritoryService, OrderService ordersService, PagingService pagingService, IMapper mapper, ILogger<EmployeesController> logger)
2122
{
2223
this.employeeService = employeeService;
2324
this.employeeTerritoryService = employeeTerritoryService;
25+
this.pagingService = pagingService;
2426
this.ordersService = ordersService;
2527
this.mapper = mapper;
2628
this.logger = logger;
@@ -41,6 +43,33 @@ public ActionResult<EmployeeDto[]> GetAll()
4143
}
4244
}
4345

46+
/// <summary>
47+
/// Fetches all employees or a page of employees based on the provided parameters.
48+
/// </summary>
49+
/// <param name="skip">The number of records to skip before starting to fetch the employees. If this parameter is not provided, fetching starts from the beginning.</param>
50+
/// <param name="top">The maximum number of employees to fetch. If this parameter is not provided, all employees are fetched.</param>
51+
/// <param name="orderBy">A comma-separated list of fields to order the employees by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
52+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
53+
[HttpGet("GetPagedEmployees")]
54+
public ActionResult<PagedResultDto<EmployeeDto>> GetAllEmployees(int? skip, int? top, string? orderBy)
55+
{
56+
try
57+
{
58+
// Retrieve all employees
59+
var employees = this.employeeService.GetAll();
60+
61+
// Get paged data
62+
var pagedResult = pagingService.GetPagedData<EmployeeDb, EmployeeDto>(employees, skip, top, orderBy);
63+
64+
return Ok(pagedResult);
65+
}
66+
catch (Exception error)
67+
{
68+
logger.LogError(error.Message);
69+
return StatusCode(500);
70+
}
71+
}
72+
4473
[HttpGet("{id}")]
4574
public ActionResult<EmployeeDto> GetById(int id)
4675
{

NorthwindCRUD/Controllers/OrdersController.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ public class OrdersController : ControllerBase
1717
private readonly CustomerService customerService;
1818
private readonly ShipperService shipperService;
1919
private readonly ProductService productService;
20+
private readonly PagingService pagingService;
2021
private readonly IMapper mapper;
2122
private readonly ILogger<OrdersController> logger;
2223

23-
public OrdersController(OrderService orderService, EmployeeService employeeService, CustomerService customerService, ShipperService shipperService, ProductService productService, IMapper mapper, ILogger<OrdersController> logger)
24+
public OrdersController(OrderService orderService, EmployeeService employeeService, CustomerService customerService, ShipperService shipperService, ProductService productService, PagingService pagingService, IMapper mapper, ILogger<OrdersController> logger)
2425
{
2526
this.orderService = orderService;
2627
this.employeeService = employeeService;
2728
this.customerService = customerService;
2829
this.shipperService = shipperService;
2930
this.productService = productService;
31+
this.pagingService = pagingService;
3032
this.mapper = mapper;
3133
this.logger = logger;
3234
}
@@ -46,6 +48,33 @@ public ActionResult<OrderDto[]> GetAll()
4648
}
4749
}
4850

51+
/// <summary>
52+
/// Fetches all orders or a page of orders based on the provided parameters.
53+
/// </summary>
54+
/// <param name="skip">The number of records to skip before starting to fetch the orders. If this parameter is not provided, fetching starts from the beginning.</param>
55+
/// <param name="top">The maximum number of orders to fetch. If this parameter is not provided, all orders are fetched.</param>
56+
/// <param name="orderBy">A comma-separated list of fields to order the orders by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
57+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
58+
[HttpGet("GetPagedOrders")]
59+
public ActionResult<PagedResultDto<OrderDto>> GetAllOrders(int? skip, int? top, string? orderBy)
60+
{
61+
try
62+
{
63+
// Retrieve all orders
64+
var orders = this.orderService.GetAll();
65+
66+
// Get paged data
67+
var pagedResult = pagingService.GetPagedData<OrderDb, OrderDto>(orders, skip, top, orderBy);
68+
69+
return Ok(pagedResult);
70+
}
71+
catch (Exception error)
72+
{
73+
logger.LogError(error.Message);
74+
return StatusCode(500);
75+
}
76+
}
77+
4978
[HttpGet("{id}")]
5079
public ActionResult<OrderDto> GetById(int id)
5180
{

NorthwindCRUD/Controllers/ProductsController.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace NorthwindCRUD.Controllers
22
{
3+
using System.Globalization;
4+
using System.Reflection;
35
using AutoMapper;
46
using Microsoft.AspNetCore.Authorization;
57
using Microsoft.AspNetCore.Mvc;
@@ -15,15 +17,17 @@ public class ProductsController : ControllerBase
1517
private readonly CategoryService categoryService;
1618
private readonly OrderService orderService;
1719
private readonly SupplierService supplierService;
20+
private readonly PagingService pagingService;
1821
private readonly IMapper mapper;
1922
private readonly ILogger<ProductsController> logger;
2023

21-
public ProductsController(ProductService productService, CategoryService categoryService, OrderService orderService, SupplierService supplierService, IMapper mapper, ILogger<ProductsController> logger)
24+
public ProductsController(ProductService productService, CategoryService categoryService, OrderService orderService, SupplierService supplierService, PagingService pagingService, IMapper mapper, ILogger<ProductsController> logger)
2225
{
2326
this.productService = productService;
2427
this.categoryService = categoryService;
2528
this.orderService = orderService;
2629
this.supplierService = supplierService;
30+
this.pagingService = pagingService;
2731
this.mapper = mapper;
2832
this.logger = logger;
2933
}
@@ -43,6 +47,33 @@ public ActionResult<ProductDto[]> GetAll()
4347
}
4448
}
4549

50+
/// <summary>
51+
/// Fetches all products or a page of products based on the provided parameters.
52+
/// </summary>
53+
/// <param name="skip">The number of records to skip before starting to fetch the products. If this parameter is not provided, fetching starts from the beginning.</param>
54+
/// <param name="top">The maximum number of products to fetch. If this parameter is not provided, all products are fetched.</param>
55+
/// <param name="orderBy">A comma-separated list of fields to order the products by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
56+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
57+
[HttpGet("GetPagedProducts")]
58+
public ActionResult<PagedResultDto<ProductDto>> GetAllProducts(int? skip, int? top, string? orderBy)
59+
{
60+
try
61+
{
62+
// Retrieve all products
63+
var products = this.productService.GetAll();
64+
65+
// Get paged data
66+
var pagedResult = pagingService.GetPagedData<ProductDb, ProductDto>(products, skip, top, orderBy);
67+
68+
return Ok(pagedResult);
69+
}
70+
catch (Exception error)
71+
{
72+
logger.LogError(error.Message);
73+
return StatusCode(500);
74+
}
75+
}
76+
4677
[HttpGet("{id}")]
4778
public ActionResult<ProductDto> GetById(int id)
4879
{

NorthwindCRUD/Controllers/RegionsController.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public class RegionsController : ControllerBase
1414
{
1515
private readonly RegionService regionService;
1616
private readonly TerritoryService territoryService;
17+
private readonly PagingService pagingService;
1718
private readonly IMapper mapper;
1819
private readonly ILogger<RegionsController> logger;
1920

20-
public RegionsController(RegionService regionService, TerritoryService territoryService, IMapper mapper, ILogger<RegionsController> logger)
21+
public RegionsController(RegionService regionService, TerritoryService territoryService, PagingService pagingService, IMapper mapper, ILogger<RegionsController> logger)
2122
{
2223
this.regionService = regionService;
2324
this.territoryService = territoryService;
25+
this.pagingService = pagingService;
2426
this.mapper = mapper;
2527
this.logger = logger;
2628
}
@@ -40,6 +42,33 @@ public ActionResult<RegionDto[]> GetAll()
4042
}
4143
}
4244

45+
/// <summary>
46+
/// Fetches all regions or a page of regions based on the provided parameters.
47+
/// </summary>
48+
/// <param name="skip">The number of records to skip before starting to fetch the regions. If this parameter is not provided, fetching starts from the beginning.</param>
49+
/// <param name="top">The maximum number of regions to fetch. If this parameter is not provided, all regions are fetched.</param>
50+
/// <param name="orderBy">A comma-separated list of fields to order the regions by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
51+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
52+
[HttpGet("GetPagedRegions")]
53+
public ActionResult<PagedResultDto<RegionDto>> GetAllRegions(int? skip, int? top, string? orderBy)
54+
{
55+
try
56+
{
57+
// Retrieve all regions
58+
var regions = this.regionService.GetAll();
59+
60+
// Get paged data
61+
var pagedResult = pagingService.GetPagedData<RegionDb, RegionDto>(regions, skip, top, orderBy);
62+
63+
return Ok(pagedResult);
64+
}
65+
catch (Exception error)
66+
{
67+
logger.LogError(error.Message);
68+
return StatusCode(500);
69+
}
70+
}
71+
4372
[HttpGet("{id}")]
4473
public ActionResult<RegionDto> GetById(int id)
4574
{

NorthwindCRUD/Controllers/ShippersController.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public class ShippersController : ControllerBase
1414
{
1515
private readonly ShipperService shipperService;
1616
private readonly OrderService orderService;
17+
private readonly PagingService pagingService;
1718
private readonly IMapper mapper;
1819
private readonly ILogger<ShippersController> logger;
1920

20-
public ShippersController(ShipperService shipperService, OrderService orderService, IMapper mapper, ILogger<ShippersController> logger)
21+
public ShippersController(ShipperService shipperService, OrderService orderService, PagingService pagingService, IMapper mapper, ILogger<ShippersController> logger)
2122
{
2223
this.shipperService = shipperService;
2324
this.orderService = orderService;
25+
this.pagingService = pagingService;
2426
this.mapper = mapper;
2527
this.logger = logger;
2628
}
@@ -40,6 +42,33 @@ public ActionResult<ShipperDto[]> GetAll()
4042
}
4143
}
4244

45+
/// <summary>
46+
/// Fetches all shippers or a page of shippers based on the provided parameters.
47+
/// </summary>
48+
/// <param name="skip">The number of records to skip before starting to fetch the shippers. If this parameter is not provided, fetching starts from the beginning.</param>
49+
/// <param name="top">The maximum number of shippers to fetch. If this parameter is not provided, all shippers are fetched.</param>
50+
/// <param name="orderBy">A comma-separated list of fields to order the shippers by, along with the sort direction (e.g., "field1 asc, field2 desc").</param>
51+
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
52+
[HttpGet("GetPagedShippers")]
53+
public ActionResult<PagedResultDto<ShipperDto>> GetAllShippers(int? skip, int? top, string? orderBy)
54+
{
55+
try
56+
{
57+
// Retrieve all shippers
58+
var shippers = this.shipperService.GetAll();
59+
60+
// Get paged data
61+
var pagedResult = pagingService.GetPagedData<ShipperDb, ShipperDto>(shippers, skip, top, orderBy);
62+
63+
return Ok(pagedResult);
64+
}
65+
catch (Exception error)
66+
{
67+
logger.LogError(error.Message);
68+
return StatusCode(500);
69+
}
70+
}
71+
4372
[HttpGet("{id}")]
4473
public ActionResult<ShipperDto> GetById(int id)
4574
{

0 commit comments

Comments
 (0)