@@ -71,45 +71,45 @@ The example below uses UmbracoApiController which is obsolete in Umbraco 14 and
7171{% endhint %}
7272
7373``` csharp
74- using System ;
75- using System .Linq ;
76- using System .Net ;
77- using System .Net .Http ;
78- using System .Web .Http ;
79- using Umbraco .Core .Services ;
80- using Umbraco .Web .WebApi ;
74+ using Microsoft .AspNetCore .Mvc ;
75+ using System .Runtime .Serialization ;
76+ using Umbraco .Cms .Core .Services ;
77+ using Umbraco .Cms .Web .Common ;
8178
8279namespace Doccers .Core .Controllers .Http ;
8380
84- public class RelationsController : UmbracoApiController
81+ [ApiController ]
82+ [Route (" /umbraco/api/relations" )]
83+ public class RelationsController : Controller
8584{
8685 private readonly IRelationService _relationService ;
86+ private readonly UmbracoHelper _umbracoHelper ;
8787
88- public RelationsController (IRelationService relationService )
88+ public RelationsController (IRelationService relationService , UmbracoHelper umbracoHelper )
8989 {
9090 // Alternatively you could also access
9191 // the service via the service context:
9292 // _relationService = Services.RelationService;
9393 _relationService = relationService ;
94+ _umbracoHelper = umbracoHelper ;
9495 }
9596
96- [HttpGet ]
97- public HttpResponseMessage GetByRelationTypeAlias (string alias )
97+ [HttpGet ( " getbyrelationtypealias " ) ]
98+ public IActionResult GetByRelationTypeAlias (string alias )
9899 {
99100 var relationType = _relationService .GetRelationTypeByAlias (alias );
100101 if (relationType == null )
101- return Request .CreateResponse (HttpStatusCode .BadRequest ,
102- " Invalid relation type alias" );
102+ return BadRequest (" Invalid relation type alias" );
103103
104104 var relations = _relationService .GetAllRelationsByRelationType (relationType .Id );
105- var content = relations .Select (x => Umbraco .Content (x .ChildId ))
105+ var content = relations .Select (x => _umbracoHelper .Content (x .ChildId ))
106106 .Select (x => new Relation ()
107107 {
108108 Name = x .Name ,
109109 UpdateDate = x .UpdateDate
110110 });
111111
112- return Request . CreateResponse ( HttpStatusCode . OK , content );
112+ return Ok ( content );
113113 }
114114}
115115```
0 commit comments