diff --git a/src/Umbraco.Web/Editors/ContentTypeController.cs b/src/Umbraco.Web/Editors/ContentTypeController.cs index 4e1417fb03..d426cb1f56 100644 --- a/src/Umbraco.Web/Editors/ContentTypeController.cs +++ b/src/Umbraco.Web/Editors/ContentTypeController.cs @@ -7,6 +7,7 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; using System.Web.Http; +using System.Web.Http.Controllers; using System.Xml; using System.Xml.Linq; using Umbraco.Core; @@ -44,6 +45,7 @@ namespace Umbraco.Web.Editors [PluginController("UmbracoApi")] [UmbracoTreeAuthorize(Constants.Trees.DocumentTypes)] [EnableOverrideAuthorization] + [ContentTypeControllerConfiguration] public class ContentTypeController : ContentTypeControllerBase { private readonly IEntityXmlSerializer _serializer; @@ -65,6 +67,17 @@ namespace Umbraco.Web.Editors _scopeProvider = scopeProvider; } + /// + /// Configures this controller with a custom action selector + /// + private class ContentTypeControllerConfigurationAttribute : 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)))); } + } + public int GetCount() { return Services.ContentTypeService.Count(); @@ -77,15 +90,58 @@ namespace Umbraco.Web.Editors return Services.ContentTypeService.HasContentNodes(id); } + /// + /// Gets the document type a given id + /// + /// + /// public DocumentTypeDisplay GetById(int id) { - var ct = Services.ContentTypeService.Get(id); - if (ct == null) + var contentType = Services.ContentTypeService.Get(id); + if (contentType == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } - var dto = Mapper.Map(ct); + var dto = Mapper.Map(contentType); + return dto; + } + + /// + /// Gets the document type a given guid + /// + /// + /// + public DocumentTypeDisplay GetById(Guid id) + { + var contentType = Services.ContentTypeService.Get(id); + if (contentType == null) + { + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + var dto = Mapper.Map(contentType); + return dto; + } + + /// + /// Gets the document type a given udi + /// + /// + /// + public DocumentTypeDisplay GetById(Udi id) + { + var guidUdi = id as GuidUdi; + if (guidUdi == null) + throw new HttpResponseException(HttpStatusCode.NotFound); + + var contentType = Services.ContentTypeService.Get(guidUdi.Guid); + if (contentType == null) + { + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + var dto = Mapper.Map(contentType); return dto; } diff --git a/src/Umbraco.Web/Editors/MediaTypeController.cs b/src/Umbraco.Web/Editors/MediaTypeController.cs index 3a4026423a..d816f13c92 100644 --- a/src/Umbraco.Web/Editors/MediaTypeController.cs +++ b/src/Umbraco.Web/Editors/MediaTypeController.cs @@ -49,6 +49,7 @@ namespace Umbraco.Web.Editors 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)), new ParameterSwapControllerActionSelector.ParameterSwapInfo("GetAllowedChildren", "contentId", typeof(int), typeof(Guid), typeof(Udi)))); } } @@ -58,21 +59,66 @@ namespace Umbraco.Web.Editors return Services.ContentTypeService.Count(); } + /// + /// Gets the media type a given id + /// + /// + /// [UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)] public MediaTypeDisplay GetById(int id) { - var ct = Services.MediaTypeService.Get(id); - if (ct == null) + var mediaType = Services.MediaTypeService.Get(id); + if (mediaType == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } - var dto = Mapper.Map(ct); + var dto = Mapper.Map(mediaType); return dto; } /// - /// Deletes a media type with a given ID + /// Gets the media type a given guid + /// + /// + /// + [UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)] + public MediaTypeDisplay GetById(Guid id) + { + var mediaType = Services.MediaTypeService.Get(id); + if (mediaType == null) + { + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + var dto = Mapper.Map(mediaType); + return dto; + } + + /// + /// Gets the media type a given udi + /// + /// + /// + [UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)] + public MediaTypeDisplay GetById(Udi id) + { + var guidUdi = id as GuidUdi; + if (guidUdi == null) + throw new HttpResponseException(HttpStatusCode.NotFound); + + var mediaType = Services.MediaTypeService.Get(guidUdi.Guid); + if (mediaType == null) + { + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + var dto = Mapper.Map(mediaType); + return dto; + } + + /// + /// Deletes a media type with a given id /// /// /// diff --git a/src/Umbraco.Web/Editors/MemberTypeController.cs b/src/Umbraco.Web/Editors/MemberTypeController.cs index fffead9155..4bfea76eda 100644 --- a/src/Umbraco.Web/Editors/MemberTypeController.cs +++ b/src/Umbraco.Web/Editors/MemberTypeController.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; +using System.Web.Http.Controllers; using System.Web.Security; using Umbraco.Core; using Umbraco.Core.Cache; @@ -16,6 +17,7 @@ using Umbraco.Core.Security; using Umbraco.Core.Services; using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Mvc; +using Umbraco.Web.WebApi; using Umbraco.Web.WebApi.Filters; using Constants = Umbraco.Core.Constants; @@ -27,6 +29,7 @@ namespace Umbraco.Web.Editors /// [PluginController("UmbracoApi")] [UmbracoTreeAuthorize(new string[] { Constants.Trees.MemberTypes, Constants.Trees.Members})] + [MemberTypeControllerConfiguration] public class MemberTypeController : ContentTypeControllerBase { public MemberTypeController(ICultureDictionaryFactory cultureDictionaryFactory, IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper) @@ -34,23 +37,80 @@ namespace Umbraco.Web.Editors { } + /// + /// Configures this controller with a custom action selector + /// + private class MemberTypeControllerConfigurationAttribute : 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)))); + } + } + private readonly MembershipProvider _provider = Core.Security.MembershipProviderExtensions.GetMembersMembershipProvider(); + /// + /// Gets the member type a given id + /// + /// + /// [UmbracoTreeAuthorize(Constants.Trees.MemberTypes)] public MemberTypeDisplay GetById(int id) { - var ct = Services.MemberTypeService.Get(id); - if (ct == null) + var memberType = Services.MemberTypeService.Get(id); + if (memberType == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } - var dto = Mapper.Map(ct); + var dto = Mapper.Map(memberType); return dto; } /// - /// Deletes a document type with a given ID + /// Gets the member type a given guid + /// + /// + /// + [UmbracoTreeAuthorize(Constants.Trees.MemberTypes)] + public MemberTypeDisplay GetById(Guid id) + { + var memberType = Services.MemberTypeService.Get(id); + if (memberType == null) + { + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + var dto = Mapper.Map(memberType); + return dto; + } + + /// + /// Gets the member type a given udi + /// + /// + /// + [UmbracoTreeAuthorize(Constants.Trees.MemberTypes)] + public MemberTypeDisplay GetById(Udi id) + { + var guidUdi = id as GuidUdi; + if (guidUdi == null) + throw new HttpResponseException(HttpStatusCode.NotFound); + + var memberType = Services.MemberTypeService.Get(guidUdi.Guid); + if (memberType == null) + { + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + var dto = Mapper.Map(memberType); + return dto; + } + + /// + /// Deletes a document type with a given id /// /// ///