diff --git a/src/Umbraco.Web/Editors/RelationTypeController.cs b/src/Umbraco.Web.BackOffice/Controllers/RelationTypeController.cs
similarity index 61%
rename from src/Umbraco.Web/Editors/RelationTypeController.cs
rename to src/Umbraco.Web.BackOffice/Controllers/RelationTypeController.cs
index b5b983c9ff..a0e0c1cb94 100644
--- a/src/Umbraco.Web/Editors/RelationTypeController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/RelationTypeController.cs
@@ -1,50 +1,49 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Net;
using System.Net.Http;
-using System.Web.Http;
-using System.Linq;
+using Microsoft.AspNetCore.Mvc;
using Umbraco.Core;
-using Umbraco.Core.Cache;
-using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
-using Umbraco.Core.Persistence;
using Umbraco.Core.Services;
using Umbraco.Core.Strings;
using Umbraco.Web.Models.ContentEditing;
-using Umbraco.Web.Mvc;
-using Umbraco.Web.WebApi;
-using Umbraco.Web.WebApi.Filters;
using Constants = Umbraco.Core.Constants;
using Umbraco.Core.Mapping;
-using Umbraco.Web.Routing;
+using Umbraco.Web.BackOffice.Filters;
+using Umbraco.Web.Common.Attributes;
+using Umbraco.Web.Common.Exceptions;
+using Umbraco.Web.Editors;
-namespace Umbraco.Web.Editors
+namespace Umbraco.Web.BackOffice.Controllers
{
///
/// The API controller for editing relation types.
///
[PluginController("UmbracoApi")]
- [UmbracoTreeAuthorize(Constants.Trees.RelationTypes)]
- [EnableOverrideAuthorization]
+ [TypeFilter(typeof(UmbracoTreeAuthorizeAttribute), Arguments = new object[]{new string[]{Constants.Trees.RelationTypes} })]
public class RelationTypeController : BackOfficeNotificationsController
{
+ private readonly ILogger _logger;
+ private readonly UmbracoMapper _umbracoMapper;
+ private readonly IRelationService _relationService;
+ private readonly IShortStringHelper _shortStringHelper;
+
public RelationTypeController(
- IGlobalSettings globalSettings,
- IUmbracoContextAccessor umbracoContextAccessor,
- ISqlContext sqlContext,
- ServiceContext services,
- AppCaches appCaches,
- IProfilingLogger logger,
- IRuntimeState runtimeState,
- IShortStringHelper shortStringHelper,
+ ILogger logger,
UmbracoMapper umbracoMapper,
- IPublishedUrlProvider publishedUrlProvider)
- : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, shortStringHelper, umbracoMapper, publishedUrlProvider)
+ IRelationService relationService,
+ IShortStringHelper shortStringHelper)
{
+ _logger = logger ?? throw new ArgumentNullException(nameof(logger));
+ _umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper));
+ _relationService = relationService ?? throw new ArgumentNullException(nameof(relationService));
+ _shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper));
}
+
///
/// Gets a relation type by ID.
///
@@ -52,14 +51,14 @@ namespace Umbraco.Web.Editors
/// Returns the .
public RelationTypeDisplay GetById(int id)
{
- var relationType = Services.RelationService.GetRelationTypeById(id);
+ var relationType = _relationService.GetRelationTypeById(id);
if (relationType == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
- var display = Mapper.Map(relationType);
+ var display = _umbracoMapper.Map(relationType);
return display;
}
@@ -73,11 +72,11 @@ namespace Umbraco.Web.Editors
}
// Ordering do we need to pass through?
- var relations = Services.RelationService.GetPagedByRelationTypeId(id, pageNumber -1, pageSize, out long totalRecords);
+ var relations = _relationService.GetPagedByRelationTypeId(id, pageNumber -1, pageSize, out long totalRecords);
return new PagedResult(totalRecords, pageNumber, pageSize)
{
- Items = relations.Select(x => Mapper.Map(x))
+ Items = relations.Select(x => _umbracoMapper.Map(x))
};
}
@@ -109,20 +108,20 @@ namespace Umbraco.Web.Editors
///
/// The relation type to create.
/// A containing the persisted relation type's ID.
- public HttpResponseMessage PostCreate(RelationTypeSave relationType)
+ public IActionResult PostCreate(RelationTypeSave relationType)
{
- var relationTypePersisted = new RelationType(relationType.Name, relationType.Name.ToSafeAlias(ShortStringHelper, true), relationType.IsBidirectional, relationType.ChildObjectType, relationType.ParentObjectType);
+ var relationTypePersisted = new RelationType(relationType.Name, relationType.Name.ToSafeAlias(_shortStringHelper, true), relationType.IsBidirectional, relationType.ChildObjectType, relationType.ParentObjectType);
try
{
- Services.RelationService.Save(relationTypePersisted);
+ _relationService.Save(relationTypePersisted);
- return Request.CreateResponse(HttpStatusCode.OK, relationTypePersisted.Id);
+ return Ok(relationTypePersisted.Id);
}
catch (Exception ex)
{
- Logger.Error(GetType(), ex, "Error creating relation type with {Name}", relationType.Name);
- return Request.CreateNotificationValidationErrorResponse("Error creating relation type.");
+ _logger.Error(GetType(), ex, "Error creating relation type with {Name}", relationType.Name);
+ throw HttpResponseException.CreateNotificationValidationErrorResponse("Error creating relation type.");
}
}
@@ -133,27 +132,27 @@ namespace Umbraco.Web.Editors
/// A display object containing the updated relation type.
public RelationTypeDisplay PostSave(RelationTypeSave relationType)
{
- var relationTypePersisted = Services.RelationService.GetRelationTypeById(relationType.Key);
+ var relationTypePersisted = _relationService.GetRelationTypeById(relationType.Key);
if (relationTypePersisted == null)
{
- throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Relation type does not exist"));
+ throw HttpResponseException.CreateNotificationValidationErrorResponse("Relation type does not exist");
}
- Mapper.Map(relationType, relationTypePersisted);
+ _umbracoMapper.Map(relationType, relationTypePersisted);
try
{
- Services.RelationService.Save(relationTypePersisted);
- var display = Mapper.Map(relationTypePersisted);
+ _relationService.Save(relationTypePersisted);
+ var display = _umbracoMapper.Map(relationTypePersisted);
display.AddSuccessNotification("Relation type saved", "");
return display;
}
catch (Exception ex)
{
- Logger.Error(GetType(), ex, "Error saving relation type with {Id}", relationType.Id);
- throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Something went wrong when saving the relation type"));
+ _logger.Error(GetType(), ex, "Error saving relation type with {Id}", relationType.Id);
+ throw HttpResponseException.CreateNotificationValidationErrorResponse("Something went wrong when saving the relation type");
}
}
@@ -164,16 +163,16 @@ namespace Umbraco.Web.Editors
/// A .
[HttpPost]
[HttpDelete]
- public HttpResponseMessage DeleteById(int id)
+ public IActionResult DeleteById(int id)
{
- var relationType = Services.RelationService.GetRelationTypeById(id);
+ var relationType = _relationService.GetRelationTypeById(id);
- if(relationType == null)
- throw new HttpResponseException(HttpStatusCode.NotFound);
+ if (relationType == null)
+ return NotFound();
- Services.RelationService.Delete(relationType);
+ _relationService.Delete(relationType);
- return Request.CreateResponse(HttpStatusCode.OK);
+ return Ok();
}
}
}
diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs
index 689fa39553..5ecb37bc48 100644
--- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs
+++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs
@@ -321,10 +321,10 @@ namespace Umbraco.Web.Editors
// "languageApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl(
// controller => controller.GetAllLanguages())
// },
- {
- "relationTypeApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl(
- controller => controller.GetById(1))
- },
+ // {
+ // "relationTypeApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl(
+ // controller => controller.GetById(1))
+ // },
// {
// "logViewerApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl(
// controller => controller.GetNumberOfErrors(null, null))
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index a5ed5fdde3..9f917ca753 100755
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -158,7 +158,6 @@
-