Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,25 +245,25 @@ The example below creates a `UmbracoApiController` to be able to fetch and inser
{% hint style="warning" %}

* 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.
* The example uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.

{% endhint %}

```csharp
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Persistence.EFCore.Scoping;
using Umbraco.Cms.Web.Common.Controllers;

namespace Umbraco.Demo;

public class BlogCommentsController : UmbracoApiController
[ApiController]
[Route("/umbraco/api/blogcomments")]
public class BlogCommentsController : Controller
{
private readonly IEFCoreScopeProvider<BlogContext> _efCoreScopeProvider;

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

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

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

[HttpPost]
[HttpPost("insertcomment")]
public async Task InsertComment(BlogComment comment)
{
using IEfCoreScope<BlogContext> scope = _efCoreScopeProvider.CreateScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,25 +245,25 @@ The example below creates a `UmbracoApiController` to be able to fetch and inser
{% hint style="warning" %}

* 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.
* The example uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.

{% endhint %}

```csharp
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Persistence.EFCore.Scoping;
using Umbraco.Cms.Web.Common.Controllers;

namespace Umbraco.Demo;

public class BlogCommentsController : UmbracoApiController
[ApiController]
[Route("/umbraco/api/blogcomments")]
public class BlogCommentsController : Controller
{
private readonly IEFCoreScopeProvider<BlogContext> _efCoreScopeProvider;

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

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

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

[HttpPost]
[HttpPost("insertcomment")]
public async Task InsertComment(BlogComment comment)
{
using IEfCoreScope<BlogContext> scope = _efCoreScopeProvider.CreateScope();
Expand Down
Loading