@@ -19,7 +19,7 @@ public NorthwindController(NorthwindContext nwind) {
1919 }
2020
2121 [ HttpGet ( "orders" ) ]
22- public async Task < object > Orders ( DataSourceLoadOptions loadOptions ) {
22+ public async Task < IActionResult > Orders ( DataSourceLoadOptions loadOptions ) {
2323 var source = _nwind . Orders . Select ( o => new {
2424 o . OrderId ,
2525 o . CustomerId ,
@@ -33,44 +33,45 @@ public async Task<object>Orders(DataSourceLoadOptions loadOptions) {
3333 loadOptions . PrimaryKey = new [ ] { "OrderId" } ;
3434 loadOptions . PaginateViaPrimaryKey = true ;
3535
36- return await DataSourceLoader . LoadAsync ( source , loadOptions ) ;
36+ return Json ( await DataSourceLoader . LoadAsync ( source , loadOptions ) ) ;
3737 }
3838
3939 [ HttpGet ( "order-details" ) ]
40- public async Task < object > OrderDetails ( int orderId , DataSourceLoadOptions options ) {
41- return await DataSourceLoader . LoadAsync (
42- from i in _nwind . OrderDetails
43- where i . OrderId == orderId
44- select new {
40+ public async Task < IActionResult > OrderDetails ( int orderId , DataSourceLoadOptions loadOptions ) {
41+ var source = _nwind . OrderDetails
42+ . Where ( i => i . OrderId == orderId )
43+ . Select ( i => new {
4544 Product = i . Product . ProductName ,
4645 Price = i . UnitPrice ,
47- Quantity = i . Quantity ,
46+ i . Quantity ,
4847 Sum = i . UnitPrice * i . Quantity
49- } ,
50- options
51- ) ;
48+ } ) ;
49+
50+ return Json ( await DataSourceLoader . LoadAsync ( source , loadOptions ) ) ;
5251 }
5352
5453 [ HttpGet ( "customers-lookup" ) ]
55- public async Task < object > CustomersLookup ( DataSourceLoadOptions options ) {
56- return await DataSourceLoader . LoadAsync (
57- from c in _nwind . Customers orderby c . CompanyName select new {
54+ public async Task < object > CustomersLookup ( DataSourceLoadOptions loadOptions ) {
55+ var source = _nwind . Customers
56+ . OrderBy ( c => c . CompanyName )
57+ . Select ( c => new {
5858 Value = c . CustomerId ,
5959 Text = $ "{ c . CompanyName } ({ c . Country } )"
60- } ,
61- options
62- ) ;
60+ } ) ;
61+
62+ return Json ( await DataSourceLoader . LoadAsync ( source , loadOptions ) ) ;
6363 }
6464
6565 [ HttpGet ( "shippers-lookup" ) ]
66- public async Task < object > ShippersLookup ( DataSourceLoadOptions options ) {
67- return await DataSourceLoader . LoadAsync (
68- from s in _nwind . Shippers orderby s . CompanyName select new {
66+ public async Task < object > ShippersLookup ( DataSourceLoadOptions loadOptions ) {
67+ var source = _nwind . Shippers
68+ . OrderBy ( s => s . CompanyName )
69+ . Select ( s => new {
6970 Value = s . ShipperId ,
7071 Text = s . CompanyName
71- } ,
72- options
73- ) ;
72+ } ) ;
73+
74+ return Json ( await DataSourceLoader . LoadAsync ( source , loadOptions ) ) ;
7475 }
7576
7677 [ HttpPut ( "update-order" ) ]
@@ -116,15 +117,15 @@ public async Task<IActionResult> DeleteOrder(int key) {
116117 }
117118
118119 [ HttpGet ( "products" ) ]
119- public async Task < object > Products ( DataSourceLoadOptions loadOptions ) {
120- var projection = _nwind . Products . Select ( p => new {
120+ public async Task < IActionResult > Products ( DataSourceLoadOptions loadOptions ) {
121+ var source = _nwind . Products . Select ( p => new {
121122 p . ProductId ,
122123 p . ProductName ,
123124 p . Category . CategoryName ,
124125 p . UnitPrice
125126 } ) ;
126127
127- return await DataSourceLoader . LoadAsync ( projection , loadOptions ) ;
128+ return Json ( await DataSourceLoader . LoadAsync ( source , loadOptions ) ) ;
128129 }
129130
130131 }
0 commit comments