@@ -71,45 +71,45 @@ The example below uses UmbracoApiController which is obsolete in Umbraco 14 and
71
71
{% endhint %}
72
72
73
73
``` 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 ;
81
78
82
79
namespace Doccers .Core .Controllers .Http ;
83
80
84
- public class RelationsController : UmbracoApiController
81
+ [ApiController ]
82
+ [Route (" /umbraco/api/relations" )]
83
+ public class RelationsController : Controller
85
84
{
86
85
private readonly IRelationService _relationService ;
86
+ private readonly UmbracoHelper _umbracoHelper ;
87
87
88
- public RelationsController (IRelationService relationService )
88
+ public RelationsController (IRelationService relationService , UmbracoHelper umbracoHelper )
89
89
{
90
90
// Alternatively you could also access
91
91
// the service via the service context:
92
92
// _relationService = Services.RelationService;
93
93
_relationService = relationService ;
94
+ _umbracoHelper = umbracoHelper ;
94
95
}
95
96
96
- [HttpGet ]
97
- public HttpResponseMessage GetByRelationTypeAlias (string alias )
97
+ [HttpGet ( " getbyrelationtypealias " ) ]
98
+ public IActionResult GetByRelationTypeAlias (string alias )
98
99
{
99
100
var relationType = _relationService .GetRelationTypeByAlias (alias );
100
101
if (relationType == null )
101
- return Request .CreateResponse (HttpStatusCode .BadRequest ,
102
- " Invalid relation type alias" );
102
+ return BadRequest (" Invalid relation type alias" );
103
103
104
104
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 ))
106
106
.Select (x => new Relation ()
107
107
{
108
108
Name = x .Name ,
109
109
UpdateDate = x .UpdateDate
110
110
});
111
111
112
- return Request . CreateResponse ( HttpStatusCode . OK , content );
112
+ return Ok ( content );
113
113
}
114
114
}
115
115
```
0 commit comments