Skip to content

Commit d5b924f

Browse files
Update Sample project (#382)
1 parent 86a0d90 commit d5b924f

6 files changed

Lines changed: 36 additions & 35 deletions

File tree

net/Sample/Controllers/NorthwindController.cs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

net/Sample/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Threading.Tasks;
66
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.Extensions.Logging;
78

89
namespace Sample {
910
public class Program {
@@ -13,6 +14,7 @@ public static void Main(string[] args) {
1314
.UseContentRoot(Directory.GetCurrentDirectory())
1415
.UseIISIntegration()
1516
.UseStartup<Startup>()
17+
.ConfigureLogging(logging => logging.AddConsole())
1618
.Build();
1719

1820
host.Run();

net/Sample/Sample.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
88
<ProjectReference Include="..\DevExtreme.AspNet.Data\DevExtreme.AspNet.Data.csproj" />
9-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" />
9+
<PackageReference Include="Microsoft.AspNetCore.App" />
1110
</ItemGroup>
1211

1312
<!-- https://github.com/dotnet/sdk/issues/1055#issuecomment-292792445 -->

net/Sample/Startup.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using Microsoft.EntityFrameworkCore;
66
using Microsoft.EntityFrameworkCore.Diagnostics;
77
using Microsoft.Extensions.DependencyInjection;
8-
using Microsoft.Extensions.Logging;
98
using Sample.Models;
109

1110
namespace Sample {
@@ -24,8 +23,7 @@ public void ConfigureServices(IServiceCollection services) {
2423
);
2524
}
2625

27-
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) {
28-
loggerFactory.AddConsole(LogLevel.Information);
26+
public void Configure(IApplicationBuilder app) {
2927
app.UseMvc();
3028
app.UseStaticFiles();
3129
}

net/Sample/Views/Home/Index.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
loadUrl: "@Url.Action("OrderDetails", "Northwind")",
9292
loadParams: { orderId: options.data.orderId }
9393
}),
94-
remoteOperations: true
94+
remoteOperations: true,
95+
showBorders: true
9596
})
9697
.appendTo(container);
9798
}

net/Sample/bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Sample",
33
"private": true,
44
"dependencies": {
5-
"devextreme": "~18.1.0",
6-
"jquery": "3.1.1"
5+
"devextreme": "~19.1.0",
6+
"jquery": "3.4.1"
77
}
88
}

0 commit comments

Comments
 (0)