Skip to content

Commit 3f855a4

Browse files
odatav4 adaptor correction
1 parent e6ab860 commit 3f855a4

File tree

9 files changed

+33
-94
lines changed

9 files changed

+33
-94
lines changed

ODataV4Adaptor/ODataV4Adaptor.Server/Controllers/OrdersController.cs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace OdataV4Adaptor.Server.Controllers
77
{
88

9-
public class OrdersController : ODataController
9+
public class OrdersController : Controller
1010
{
1111
/// <summary>
1212
/// Retrieves all orders.
@@ -21,61 +21,60 @@ public IActionResult Get()
2121
}
2222

2323
/// <summary>
24-
/// Creates a new order.
24+
/// Inserts a new order to the collection.
2525
/// </summary>
26-
/// <param name="order">The order to be created.</param>
27-
/// <returns>The newly created order.</returns>
26+
/// <param name="addRecord">The order to be inserted.</param>
27+
/// <returns>It returns the newly inserted record detail.</returns>
2828
[HttpPost]
2929
[EnableQuery]
30-
public IActionResult Post([FromBody] OrdersDetails order)
30+
public IActionResult Post([FromBody] OrdersDetails addRecord)
3131
{
32-
if (order == null)
32+
if (addRecord == null)
3333
{
34-
return BadRequest("Null order");
34+
return BadRequest("Null order");
3535
}
36-
37-
OrdersDetails.GetAllRecords().Insert(0, order);
38-
return Ok(order);
36+
OrdersDetails.GetAllRecords().Insert(0, addRecord);
37+
return Json(addRecord);
3938
}
4039

4140
/// <summary>
4241
/// Updates an existing order.
4342
/// </summary>
44-
/// <param name="key">The key of the order to be updated.</param>
45-
/// <param name="updatedOrder">The updated order details.</param>
46-
/// <returns>The updated order.</returns>
43+
/// <param name="key">The ID of the order to update.</param>
44+
/// <param name="updateRecord">The updated order details.</param>
45+
/// <returns>It returns the updated order details.</returns>
4746
[HttpPatch("{key}")]
48-
public IActionResult Patch(int key, [FromBody] OrdersDetails updatedOrder)
47+
public IActionResult Patch(int key, [FromBody] OrdersDetails updateRecord)
4948
{
50-
if (updatedOrder == null)
49+
if (updateRecord == null)
5150
{
5251
return BadRequest("No records");
5352
}
54-
var existingOrder = OrdersDetails.GetAllRecords().FirstOrDefault(o => o.OrderID == key);
53+
var existingOrder = OrdersDetails.GetAllRecords().FirstOrDefault(order => order.OrderID == key);
5554
if (existingOrder != null)
5655
{
5756
// If the order exists, update its properties
58-
existingOrder.CustomerID = updatedOrder.CustomerID ?? existingOrder.CustomerID;
59-
existingOrder.EmployeeID = updatedOrder.EmployeeID ?? existingOrder.EmployeeID;
60-
existingOrder.ShipCountry = updatedOrder.ShipCountry ?? existingOrder.ShipCountry;
57+
existingOrder.CustomerID = updateRecord.CustomerID ?? existingOrder.CustomerID;
58+
existingOrder.EmployeeID = updateRecord.EmployeeID ?? existingOrder.EmployeeID;
59+
existingOrder.ShipCountry = updateRecord.ShipCountry ?? existingOrder.ShipCountry;
6160
}
62-
return Ok(existingOrder);
61+
return Json(updateRecord);
6362
}
6463

6564
/// <summary>
6665
/// Deletes an order.
6766
/// </summary>
68-
/// <param name="key">The key of the order to be deleted.</param>
69-
/// <returns>The deleted order.</returns>
67+
/// <param name="key">The ID of the order to delete.</param>
68+
/// <returns>It returns the deleted record detail</returns>
7069
[HttpDelete("{key}")]
7170
public IActionResult Delete(int key)
7271
{
73-
var order = OrdersDetails.GetAllRecords().FirstOrDefault(o => o.OrderID == key);
74-
if (order != null)
72+
var deleteRecord = OrdersDetails.GetAllRecords().FirstOrDefault(order => order.OrderID == key);
73+
if (deleteRecord != null)
7574
{
76-
OrdersDetails.GetAllRecords().Remove(order);
75+
OrdersDetails.GetAllRecords().Remove(deleteRecord);
7776
}
78-
return Ok(order);
77+
return Json(deleteRecord);
7978
}
8079
}
8180
}

ODataV4Adaptor/ODataV4Adaptor.Server/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
var modelBuilder = new ODataConventionModelBuilder();
99
modelBuilder.EntitySet<OrdersDetails>("Orders");
1010

11+
var recordCount = OrdersDetails.GetAllRecords().Count;
12+
1113
builder.Services.AddControllers().AddOData(
1214
options => options
1315
.Count()
14-
.SetMaxTop(null)
16+
.OrderBy()
17+
.Filter()
18+
.SetMaxTop(recordCount)
1519
.AddRouteComponents(
1620
"odata",
1721
modelBuilder.GetEdmModel()));

ODataV4Adaptor/ODataV4Adaptor.Server/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs

Lines changed: 0 additions & 4 deletions
This file was deleted.

ODataV4Adaptor/ODataV4Adaptor.Server/obj/Debug/net8.0/ODataV4Adaptor.Server.AssemblyInfo.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

ODataV4Adaptor/ODataV4Adaptor.Server/obj/Debug/net8.0/ODataV4Adaptor.Server.AssemblyInfoInputs.cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

ODataV4Adaptor/ODataV4Adaptor.Server/obj/Debug/net8.0/ODataV4Adaptor.Server.GeneratedMSBuildEditorConfig.editorconfig

Lines changed: 0 additions & 19 deletions
This file was deleted.

ODataV4Adaptor/ODataV4Adaptor.Server/obj/Debug/net8.0/ODataV4Adaptor.Server.GlobalUsings.g.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

ODataV4Adaptor/odatav4adaptor.client/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ejs-grid #grid [dataSource]='data' allowPaging="true">
1+
<ejs-grid #grid [dataSource]='data' allowPaging="true" allowSorting="true" allowFiltering="true" [editSettings]="editSettings" [toolbar]="toolbar" >
22
<e-columns>
33
<e-column field='OrderID' headerText='Order ID' isPrimaryKey=true width='150'></e-column>
44
<e-column field='CustomerID' headerText='Customer Name' width='150'></e-column>

ODataV4Adaptor/odatav4adaptor.client/src/app/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BrowserModule } from '@angular/platform-browser';
44

55
import { AppRoutingModule } from './app-routing.module';
66
import { AppComponent } from './app.component';
7-
import { EditService, GridModule, PageService, ToolbarService } from '@syncfusion/ej2-angular-grids';
7+
import { EditService, FilterService, GridModule, PageService, SortService, ToolbarService } from '@syncfusion/ej2-angular-grids';
88

99
@NgModule({
1010
declarations: [
@@ -15,7 +15,7 @@ import { EditService, GridModule, PageService, ToolbarService } from '@syncfusio
1515
AppRoutingModule,
1616
GridModule
1717
],
18-
providers: [EditService, ToolbarService, PageService],
18+
providers: [EditService, ToolbarService, PageService, SortService, FilterService],
1919
bootstrap: [AppComponent]
2020
})
2121
export class AppModule { }

0 commit comments

Comments
 (0)