Skip to content

Commit

Permalink
Update Odata sample with AspNetCoreOData 8.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavnavar committed Jul 16, 2021
1 parent 4e6b64b commit b8688b9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion GridBlazorOData.Server/Controllers/EmployeesController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using GridBlazorOData.Server.Models;
using GridBlazorOData.Shared.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Deltas;
using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Formatter.Value;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Routing.Controllers;
using Microsoft.EntityFrameworkCore;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using GridBlazorOData.Server.Models;
using GridBlazorOData.Shared.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Deltas;
using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Formatter.Value;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Routing.Controllers;
using Microsoft.EntityFrameworkCore;
Expand Down
21 changes: 7 additions & 14 deletions GridBlazorOData.Server/Controllers/OrdersController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using GridBlazorOData.Server.Models;
using GridBlazorOData.Shared.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Deltas;
using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Formatter.Value;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Routing.Attributes;
using Microsoft.AspNetCore.OData.Routing.Controllers;
using Microsoft.EntityFrameworkCore;
using System;
Expand Down Expand Up @@ -151,8 +150,7 @@ private bool OrderExists(int key)
}

[EnableQuery]
[HttpGet]
[ODataRoute("Orders({keyOrderID})/OrderDetails")]
[HttpGet("Orders({keyOrderID})/OrderDetails")]
public IActionResult GetOrderDetails(int keyOrderID)
{
var repository = new OrderDetailsRepository(_context);
Expand All @@ -161,17 +159,15 @@ public IActionResult GetOrderDetails(int keyOrderID)
}

[EnableQuery]
[HttpGet]
[ODataRoute("Orders({orderID})/OrderDetails({keyOrderID},{keyProductID})")]
[HttpGet("Orders({orderID})/OrderDetails({keyOrderID},{keyProductID})")]
public async Task<IActionResult> GetOrderDetails([FromODataUri] int keyOrderID, [FromODataUri] int keyProductID)
{
var repository = new OrderDetailsRepository(_context);
OrderDetail orderDetail = await repository.GetById(new { OrderID = keyOrderID, ProductID = keyProductID });
return Ok(orderDetail);
}

[HttpPost]
[ODataRoute("Orders({keyOrderID})/OrderDetails")]
[HttpPost("Orders({keyOrderID})/OrderDetails")]
public async Task<IActionResult> PostToOrderDetails([FromODataUri] int keyOrderID, [FromBody] OrderDetail orderdetail)
{
if (!ModelState.IsValid)
Expand Down Expand Up @@ -201,8 +197,7 @@ public async Task<IActionResult> PostToOrderDetails([FromODataUri] int keyOrderI
}
}

[HttpPatch]
[ODataRoute("Orders({orderID})/OrderDetails({keyOrderID},{keyProductID})")]
[HttpPatch("Orders({orderID})/OrderDetails({keyOrderID},{keyProductID})")]
public async Task<IActionResult> PatchToOrderDetails([FromODataUri] int keyOrderID, [FromODataUri] int keyProductID,
[FromBody] Delta<OrderDetail> orderDetail)
{
Expand Down Expand Up @@ -236,8 +231,7 @@ public async Task<IActionResult> PatchToOrderDetails([FromODataUri] int keyOrder
return Updated(entity);
}

[HttpPut]
[ODataRoute("Orders({orderID})/OrderDetails({keyOrderID},{keyProductID})")]
[HttpPut("Orders({orderID})/OrderDetails({keyOrderID},{keyProductID})")]
public async Task<IActionResult> PutToOrderDetails([FromODataUri] int keyOrderID, [FromODataUri] int keyProductID,
[FromBody] OrderDetail orderDetail)
{
Expand Down Expand Up @@ -270,8 +264,7 @@ public async Task<IActionResult> PutToOrderDetails([FromODataUri] int keyOrderID
return Updated(orderDetail);
}

[HttpDelete]
[ODataRoute("Orders({orderID})/OrderDetails({keyOrderID},{keyProductID})")]
[HttpDelete("Orders({orderID})/OrderDetails({keyOrderID},{keyProductID})")]
public async Task<ActionResult> DeleteToOrderDetails([FromODataUri] int keyOrderID, [FromODataUri] int keyProductID)
{
var repository = new OrderDetailsRepository(_context);
Expand Down
4 changes: 2 additions & 2 deletions GridBlazorOData.Server/GridBlazorOData.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<DisableImplicitComponentsAnalyzers>true</DisableImplicitComponentsAnalyzers>
<Version>2.1.6</Version>
<Version>2.1.18</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="5.0.2" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="8.0.0-preview3" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="8.0.1" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Text.Json" Version="5.0.1" />
</ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions GridBlazorOData.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public void ConfigureServices(IServiceCollection services)
});
});

services.AddControllers();
services.AddOData(opt => opt.AddModel("odata", EdmModel.GetEdmModel())
services.AddControllers().AddOData(opt => opt.AddRouteComponents("odata", EdmModel.GetEdmModel())
.Select().Expand().Filter().OrderBy().SetMaxTop(null).Count());
}

Expand Down

0 comments on commit b8688b9

Please sign in to comment.