Skip to content

Commit da3c6bd

Browse files
authored
Merge pull request #6529 from erikjanwestendorp/update-mapping
Porting old Umbraco API Controller [Mapping]
2 parents 9399fea + 8591b02 commit da3c6bd

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

14/umbraco-cms/reference/mapping.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,6 @@ The analyzer follows the standard analyzer development patterns, and building th
189189

190190
Below you will find a full example showing you how to map a collection of type Product to a collection of type ProductDto.
191191

192-
{% hint style="warning" %}
193-
The example below uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.
194-
{% endhint %}
195-
196192
```csharp
197193
#region Models
198194

@@ -241,28 +237,30 @@ public class ProductComposer : IComposer
241237

242238
#endregion
243239

244-
public class ProductsController : UmbracoApiController
240+
[ApiController]
241+
[Route("/umbraco/api/products")]
242+
public class ProductsController : Controller
245243
{
246244
private readonly IUmbracoMapper _mapper;
247245

248246
public ProductsController(IUmbracoMapper mapper) => _mapper = mapper;
249247

250-
[HttpGet]
251-
public HttpResponseMessage GetAll()
248+
[HttpGet("getall")]
249+
public IActionResult GetAll()
252250
{
253251
var products = FakeServiceCall();
254252
var mapped = _mapper.MapEnumerable<Product, ProductDto>(products);
255253

256-
return Request.CreateResponse(HttpStatusCode.OK, mapped);
254+
return Ok(mapped);
257255
}
258256

259-
[HttpGet]
260-
public HttpResponseMessage GetFirstProduct()
257+
[HttpGet("getfirstproduct")]
258+
public IActionResult GetFirstProduct()
261259
{
262260
var product = FakeServiceCall().First();
263261
var mapped = _mapper.Map<ProductDto>(product);
264262

265-
return Request.CreateResponse(HttpStatusCode.OK, mapped);
263+
return Ok(mapped);
266264
}
267265

268266
private IEnumerable<Product> FakeServiceCall()

15/umbraco-cms/reference/mapping.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,6 @@ The analyzer follows the standard analyzer development patterns, and building th
189189

190190
Below you will find a full example showing you how to map a collection of type Product to a collection of type ProductDto.
191191

192-
{% hint style="warning" %}
193-
The example below uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.
194-
{% endhint %}
195-
196192
```csharp
197193
#region Models
198194

@@ -241,28 +237,30 @@ public class ProductComposer : IComposer
241237

242238
#endregion
243239

244-
public class ProductsController : UmbracoApiController
240+
[ApiController]
241+
[Route("/umbraco/api/products")]
242+
public class ProductsController : Controller
245243
{
246244
private readonly IUmbracoMapper _mapper;
247245

248246
public ProductsController(IUmbracoMapper mapper) => _mapper = mapper;
249247

250-
[HttpGet]
251-
public HttpResponseMessage GetAll()
248+
[HttpGet("getall")]
249+
public IActionResult GetAll()
252250
{
253251
var products = FakeServiceCall();
254252
var mapped = _mapper.MapEnumerable<Product, ProductDto>(products);
255253

256-
return Request.CreateResponse(HttpStatusCode.OK, mapped);
254+
return Ok(mapped);
257255
}
258256

259-
[HttpGet]
260-
public HttpResponseMessage GetFirstProduct()
257+
[HttpGet("getfirstproduct")]
258+
public IActionResult GetFirstProduct()
261259
{
262260
var product = FakeServiceCall().First();
263261
var mapped = _mapper.Map<ProductDto>(product);
264262

265-
return Request.CreateResponse(HttpStatusCode.OK, mapped);
263+
return Ok(mapped);
266264
}
267265

268266
private IEnumerable<Product> FakeServiceCall()

0 commit comments

Comments
 (0)