diff --git a/src/Umbraco.Web/Editors/RelationTypeController.cs b/src/Umbraco.Web/Editors/RelationTypeController.cs
index f12faf77cc..3e45600be9 100644
--- a/src/Umbraco.Web/Editors/RelationTypeController.cs
+++ b/src/Umbraco.Web/Editors/RelationTypeController.cs
@@ -17,6 +17,7 @@ using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
using Umbraco.Web.WebApi.Filters;
using Constants = Umbraco.Core.Constants;
+using System.Web.Http.Controllers;
namespace Umbraco.Web.Editors
{
@@ -26,6 +27,7 @@ namespace Umbraco.Web.Editors
[PluginController("UmbracoApi")]
[UmbracoTreeAuthorize(Constants.Trees.RelationTypes)]
[EnableOverrideAuthorization]
+ [RelationTypeControllerConfiguration]
public class RelationTypeController : BackOfficeNotificationsController
{
public RelationTypeController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper)
@@ -34,22 +36,65 @@ namespace Umbraco.Web.Editors
}
///
- /// Gets a relation type by ID.
+ /// Configures this controller with a custom action selector
+ ///
+ private class RelationTypeControllerConfigurationAttribute : Attribute, IControllerConfiguration
+ {
+ public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
+ {
+ controllerSettings.Services.Replace(typeof(IHttpActionSelector), new ParameterSwapControllerActionSelector(
+ new ParameterSwapControllerActionSelector.ParameterSwapInfo("GetById", "id", typeof(int), typeof(Guid), typeof(Udi))
+ ));
+ }
+ }
+
+ ///
+ /// Gets a relation type by id
///
/// The relation type ID.
/// Returns the .
public RelationTypeDisplay GetById(int id)
{
var relationType = Services.RelationService.GetRelationTypeById(id);
-
if (relationType == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
+ return Mapper.Map(relationType);
+ }
- var display = Mapper.Map(relationType);
-
- return display;
+ ///
+ /// Gets a relation type by guid
+ ///
+ /// The relation type ID.
+ /// Returns the .
+ public RelationTypeDisplay GetById(Guid id)
+ {
+ var relationType = Services.RelationService.GetRelationTypeById(id);
+ if (relationType == null)
+ {
+ throw new HttpResponseException(HttpStatusCode.NotFound);
+ }
+ return Mapper.Map(relationType);
+ }
+
+ ///
+ /// Gets a relation type by udi
+ ///
+ /// The relation type ID.
+ /// Returns the .
+ public RelationTypeDisplay GetById(Udi id)
+ {
+ var guidUdi = id as GuidUdi;
+ if (guidUdi == null)
+ throw new HttpResponseException(HttpStatusCode.NotFound);
+
+ var relationType = Services.RelationService.GetRelationTypeById(guidUdi.Guid);
+ if (relationType == null)
+ {
+ throw new HttpResponseException(HttpStatusCode.NotFound);
+ }
+ return Mapper.Map(relationType);
}
public PagedResult GetPagedResults(int id, int pageNumber = 1, int pageSize = 100)