Skip to content

Commit 7aa9de4

Browse files
authored
Merge pull request #6580 from erikjanwestendorp/update-getting-started-with-ef
Porting old Umbraco API Controller [Getting started with Entity Framework (EF) Core]
2 parents 32c452f + 20325fe commit 7aa9de4

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

14/umbraco-cms/tutorials/getting-started-with-entity-framework-core.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,25 +245,25 @@ The example below creates a `UmbracoApiController` to be able to fetch and inser
245245
{% hint style="warning" %}
246246

247247
* This example uses the `BlogComment` class, which is a database model. The recommended approach would be to map these over to a ViewModel instead, that way your database & UI layers are not coupled. Be aware that things like error handling and data validation have been omitted for brevity.
248-
* The example uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.
249248

250249
{% endhint %}
251250

252251
```csharp
253252
using Microsoft.AspNetCore.Mvc;
254253
using Umbraco.Cms.Persistence.EFCore.Scoping;
255-
using Umbraco.Cms.Web.Common.Controllers;
256254

257255
namespace Umbraco.Demo;
258256

259-
public class BlogCommentsController : UmbracoApiController
257+
[ApiController]
258+
[Route("/umbraco/api/blogcomments")]
259+
public class BlogCommentsController : Controller
260260
{
261261
private readonly IEFCoreScopeProvider<BlogContext> _efCoreScopeProvider;
262262

263263
public BlogCommentsController(IEFCoreScopeProvider<BlogContext> efCoreScopeProvider)
264264
=> _efCoreScopeProvider = efCoreScopeProvider;
265265

266-
[HttpGet]
266+
[HttpGet("all")]
267267
public async Task<IActionResult> All()
268268
{
269269
using IEfCoreScope<BlogContext> scope = _efCoreScopeProvider.CreateScope();
@@ -272,7 +272,7 @@ public class BlogCommentsController : UmbracoApiController
272272
return Ok(comments);
273273
}
274274

275-
[HttpGet]
275+
[HttpGet("getcomments")]
276276
public async Task<IActionResult> GetComments(Guid umbracoNodeKey)
277277
{
278278
using IEfCoreScope<BlogContext> scope = _efCoreScopeProvider.CreateScope();
@@ -285,7 +285,7 @@ public class BlogCommentsController : UmbracoApiController
285285
return Ok(comments);
286286
}
287287

288-
[HttpPost]
288+
[HttpPost("insertcomment")]
289289
public async Task InsertComment(BlogComment comment)
290290
{
291291
using IEfCoreScope<BlogContext> scope = _efCoreScopeProvider.CreateScope();

15/umbraco-cms/tutorials/getting-started-with-entity-framework-core.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,25 +245,25 @@ The example below creates a `UmbracoApiController` to be able to fetch and inser
245245
{% hint style="warning" %}
246246

247247
* This example uses the `BlogComment` class, which is a database model. The recommended approach would be to map these over to a ViewModel instead, that way your database & UI layers are not coupled. Be aware that things like error handling and data validation have been omitted for brevity.
248-
* The example uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.
249248

250249
{% endhint %}
251250

252251
```csharp
253252
using Microsoft.AspNetCore.Mvc;
254253
using Umbraco.Cms.Persistence.EFCore.Scoping;
255-
using Umbraco.Cms.Web.Common.Controllers;
256254

257255
namespace Umbraco.Demo;
258256

259-
public class BlogCommentsController : UmbracoApiController
257+
[ApiController]
258+
[Route("/umbraco/api/blogcomments")]
259+
public class BlogCommentsController : Controller
260260
{
261261
private readonly IEFCoreScopeProvider<BlogContext> _efCoreScopeProvider;
262262

263263
public BlogCommentsController(IEFCoreScopeProvider<BlogContext> efCoreScopeProvider)
264264
=> _efCoreScopeProvider = efCoreScopeProvider;
265265

266-
[HttpGet]
266+
[HttpGet("all")]
267267
public async Task<IActionResult> All()
268268
{
269269
using IEfCoreScope<BlogContext> scope = _efCoreScopeProvider.CreateScope();
@@ -272,7 +272,7 @@ public class BlogCommentsController : UmbracoApiController
272272
return Ok(comments);
273273
}
274274

275-
[HttpGet]
275+
[HttpGet("getcomments")]
276276
public async Task<IActionResult> GetComments(Guid umbracoNodeKey)
277277
{
278278
using IEfCoreScope<BlogContext> scope = _efCoreScopeProvider.CreateScope();
@@ -285,7 +285,7 @@ public class BlogCommentsController : UmbracoApiController
285285
return Ok(comments);
286286
}
287287

288-
[HttpPost]
288+
[HttpPost("insertcomment")]
289289
public async Task InsertComment(BlogComment comment)
290290
{
291291
using IEfCoreScope<BlogContext> scope = _efCoreScopeProvider.CreateScope();

0 commit comments

Comments
 (0)