Skip to content

Commit 21b0fe6

Browse files
Adding sample for ODataV4Adaptor
1 parent 6f7f026 commit 21b0fe6

File tree

10 files changed

+45
-49
lines changed

10 files changed

+45
-49
lines changed

ODataV4Adaptor/ODataV4Adaptor.sln

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.9.34728.123
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODataV4Adaptor", "ODataV4Adaptor\ODataV4Adaptor.csproj", "{CAB1491F-D43B-4513-9A9D-F5A56AA8F093}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODataV4Adaptor", "ODataV4Adaptor\ODataV4Adaptor.csproj", "{74ADB429-2FE7-4393-977B-D519A96C236C}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
1111
Release|Any CPU = Release|Any CPU
1212
EndGlobalSection
1313
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14-
{CAB1491F-D43B-4513-9A9D-F5A56AA8F093}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15-
{CAB1491F-D43B-4513-9A9D-F5A56AA8F093}.Debug|Any CPU.Build.0 = Debug|Any CPU
16-
{CAB1491F-D43B-4513-9A9D-F5A56AA8F093}.Release|Any CPU.ActiveCfg = Release|Any CPU
17-
{CAB1491F-D43B-4513-9A9D-F5A56AA8F093}.Release|Any CPU.Build.0 = Release|Any CPU
14+
{74ADB429-2FE7-4393-977B-D519A96C236C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{74ADB429-2FE7-4393-977B-D519A96C236C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{74ADB429-2FE7-4393-977B-D519A96C236C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{74ADB429-2FE7-4393-977B-D519A96C236C}.Release|Any CPU.Build.0 = Release|Any CPU
1818
EndGlobalSection
1919
GlobalSection(SolutionProperties) = preSolution
2020
HideSolutionNode = FALSE
2121
EndGlobalSection
2222
GlobalSection(ExtensibilityGlobals) = postSolution
23-
SolutionGuid = {C4A3478D-2390-4B78-982F-E0AC583C0E9D}
23+
SolutionGuid = {3927FC0F-643B-423D-B5D3-E6D66A7D9934}
2424
EndGlobalSection
2525
EndGlobal

ODataV4Adaptor/ODataV4Adaptor/Controllers/OrdersController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.AspNetCore.OData.Query;
33
using Microsoft.AspNetCore.OData.Routing.Controllers;
44
using ODataV4Adaptor.Models;
5+
56
namespace OdataV4Adaptor.Controllers
67
{
78

@@ -54,7 +55,7 @@ public IActionResult Patch(int key, [FromBody] OrdersDetails updateRecord)
5455
{
5556
// If the order exists, update its properties
5657
existingOrder.CustomerID = updateRecord.CustomerID ?? existingOrder.CustomerID;
57-
existingOrder.ShipCity = updateRecord.ShipCity ?? existingOrder.ShipCity;
58+
existingOrder.EmployeeID = updateRecord.EmployeeID ?? existingOrder.EmployeeID;
5859
existingOrder.ShipCountry = updateRecord.ShipCountry ?? existingOrder.ShipCountry;
5960
}
6061
return Json(updateRecord);

ODataV4Adaptor/ODataV4Adaptor/Models/OrdersDetails.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public OrdersDetails()
1010

1111
}
1212
public OrdersDetails(
13-
int OrderID, string CustomerId, string ShipCity, string ShipCountry)
13+
int OrderID, string CustomerId, int EmployeeId, string ShipCountry)
1414
{
1515
this.OrderID = OrderID;
1616
this.CustomerID = CustomerId;
17-
this.ShipCity = ShipCity;
17+
this.EmployeeID = EmployeeId;
1818
this.ShipCountry = ShipCountry;
1919
}
2020

@@ -25,20 +25,23 @@ public static List<OrdersDetails> GetAllRecords()
2525
int code = 10000;
2626
for (int i = 1; i < 10; i++)
2727
{
28-
order.Add(new OrdersDetails(code + 1, "ALFKI","Berlin", "Denmark"));
29-
order.Add(new OrdersDetails(code + 2, "ANATR", "Madrid", "Brazil"));
30-
order.Add(new OrdersDetails(code + 3, "ANTON", "Cholchester", "Germany"));
31-
order.Add(new OrdersDetails(code + 4, "BLONP", "Marseille", "Austria"));
32-
order.Add(new OrdersDetails(code + 5, "BOLID", "tsawassen", "Switzerland"));
28+
order.Add(new OrdersDetails(code + 1, "ALFKI", i + 0, "Denmark"));
29+
order.Add(new OrdersDetails(code + 2, "ANATR", i + 2, "Brazil"));
30+
order.Add(new OrdersDetails(code + 3, "ANTON", i + 1, "Germany"));
31+
order.Add(new OrdersDetails(code + 4, "BLONP", i + 3, "Austria"));
32+
order.Add(new OrdersDetails(code + 5, "BOLID", i + 4, "Switzerland"));
3333
code += 5;
3434
}
3535
}
3636
return order;
3737
}
3838
[Key]
3939
public int? OrderID { get; set; }
40+
[Required]
4041
public string? CustomerID { get; set; }
41-
public string? ShipCity { get; set; }
42+
[Required]
43+
public int? EmployeeID { get; set; }
44+
[Required]
4245
public string? ShipCountry { get; set; }
4346
}
4447
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
@@ -11,8 +11,4 @@
1111
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
1212
</ItemGroup>
1313

14-
<ItemGroup>
15-
<Folder Include="wwwroot\css\" />
16-
</ItemGroup>
17-
1814
</Project>

ODataV4Adaptor/ODataV4Adaptor/ODataV4Adaptor.csproj.user

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<ActiveDebugProfile>https</ActiveDebugProfile>
5-
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
6-
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
75
</PropertyGroup>
86
</Project>

ODataV4Adaptor/ODataV4Adaptor/ODataV4Adaptor.http

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@ODataV4Adaptor_HostAddress = http://localhost:5214
1+
@ODataV4Adaptor_HostAddress = http://localhost:5063
22

33
GET {{ODataV4Adaptor_HostAddress}}/weatherforecast/
44
Accept: application/json

ODataV4Adaptor/ODataV4Adaptor/Program.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,22 @@
1717
// Register the "Orders" entity set with the OData model builder
1818
modelBuilder.EntitySet<OrdersDetails>("Orders");
1919

20-
var recordCount = OrdersDetails.GetAllRecords().Count;
20+
// Add controllers with OData support to the service collection
2121

22+
var recordCount = OrdersDetails.GetAllRecords().Count;
2223
builder.Services.AddControllers().AddOData(
2324
options => options
24-
.Count()
25-
.OrderBy()
26-
.Filter()
27-
.SetMaxTop(recordCount)
28-
.AddRouteComponents(
29-
"odata",
30-
modelBuilder.GetEdmModel()));
25+
.Count()
26+
.Filter() //searching and filtering
27+
.Select()
28+
.Expand()
29+
.OrderBy()
30+
.SetMaxTop(recordCount)
31+
.AddRouteComponents("odata", modelBuilder.GetEdmModel()));
3132

3233
var app = builder.Build();
33-
3434
app.UseDefaultFiles();
3535
app.UseStaticFiles();
36-
3736
// Configure the HTTP request pipeline.
3837
if (app.Environment.IsDevelopment())
3938
{

ODataV4Adaptor/ODataV4Adaptor/Properties/launchSettings.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"windowsAuthentication": false,
55
"anonymousAuthentication": true,
66
"iisExpress": {
7-
"applicationUrl": "http://localhost:5430",
8-
"sslPort": 44372
7+
"applicationUrl": "http://localhost:13228",
8+
"sslPort": 44361
99
}
1010
},
1111
"profiles": {
@@ -14,7 +14,7 @@
1414
"dotnetRunMessages": true,
1515
"launchBrowser": true,
1616
"launchUrl": "swagger",
17-
"applicationUrl": "http://localhost:5214",
17+
"applicationUrl": "http://localhost:5063",
1818
"environmentVariables": {
1919
"ASPNETCORE_ENVIRONMENT": "Development"
2020
}
@@ -24,7 +24,7 @@
2424
"dotnetRunMessages": true,
2525
"launchBrowser": true,
2626
// "launchUrl": "swagger",
27-
"applicationUrl": "https://localhost:7047;http://localhost:5214",
27+
"applicationUrl": "https://localhost:7116;http://localhost:5063",
2828
"environmentVariables": {
2929
"ASPNETCORE_ENVIRONMENT": "Development"
3030
}

ODataV4Adaptor/ODataV4Adaptor/wwwroot/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<title>ODataV4Adaptor</title>
4+
<title>EJ2 Grid</title>
55
<meta charset="utf-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<meta name="description" content="Typescript Grid Control">
7+
<meta name="description" content="Javascript Grid Control">
88
<meta name="author" content="Syncfusion">
9+
<link href="css/index.css" rel="stylesheet">
910
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-base/styles/material.css" rel="stylesheet">
1011
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-grids/styles/material.css" rel="stylesheet">
1112
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-buttons/styles/material.css" rel="stylesheet">
@@ -27,7 +28,6 @@
2728
<div id="container">
2829
<div id="Grid"></div>
2930
</div>
30-
3131
<script src="js/index.js" type="text/javascript"></script>
3232
</body>
3333
</html>

ODataV4Adaptor/ODataV4Adaptor/wwwroot/js/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
var data = new ej.data.DataManager({
2-
url: 'https://localhost:7047/odata/Orders',
1+
var data = new ej.data.DataManager({
2+
url: 'https://localhost:7116/odata/orders', // Here xxxx represents the port number
33
adaptor: new ej.data.ODataV4Adaptor()
44
});
5-
ej.grids.Grid.Inject(ej.grids.Toolbar, ej.grids.Edit, ej.grids.Filter, ej.grids.Page, ej.grids.Sort);
6-
5+
ej.grids.Grid.Inject(ej.grids.Toolbar, ej.grids.Filter, ej.grids.Sort, ej.grids.Page, ej.grids.Edit);
76
var grid = new ej.grids.Grid({
87
dataSource: data,
9-
allowPaging: true,
10-
allowSorting: true,
118
allowFiltering: true,
12-
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel', 'Search'],
13-
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' },
9+
allowSorting:true,
10+
toolbar: ['Add', 'Edit', 'Update', 'Delete', 'Cancel', 'Search'],
11+
filterSettings: { type:'Excel' },
12+
editSettings: { allowAdding: true, allowDeleting: true, allowEditing: true },
1413
columns: [
1514
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, isPrimaryKey: true, type: 'number' },
1615
{ field: 'CustomerID', width: 140, headerText: 'Customer ID', type: 'string' },
17-
{ field: 'ShipCity', headerText: 'ShipCity', width: 140 },
16+
{ field: 'EmployeeID', headerText: 'Employee ID', width: 140 },
1817
{ field: 'ShipCountry', headerText: 'ShipCountry', width: 140 }
1918
]
2019
});

0 commit comments

Comments
 (0)