diff --git a/src/Umbraco.Core/Services/IMemberGroupService.cs b/src/Umbraco.Core/Services/IMemberGroupService.cs index 6a554aad31..9261dcfdf6 100644 --- a/src/Umbraco.Core/Services/IMemberGroupService.cs +++ b/src/Umbraco.Core/Services/IMemberGroupService.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Umbraco.Core.Models; namespace Umbraco.Core.Services @@ -7,6 +8,7 @@ namespace Umbraco.Core.Services { IEnumerable GetAll(); IMemberGroup GetById(int id); + IMemberGroup GetById(Guid id); IEnumerable GetByIds(IEnumerable ids); IMemberGroup GetByName(string name); void Save(IMemberGroup memberGroup, bool raiseEvents = true); diff --git a/src/Umbraco.Core/Services/Implement/MemberGroupService.cs b/src/Umbraco.Core/Services/Implement/MemberGroupService.cs index c879a00ccb..d0f40f83a7 100644 --- a/src/Umbraco.Core/Services/Implement/MemberGroupService.cs +++ b/src/Umbraco.Core/Services/Implement/MemberGroupService.cs @@ -70,6 +70,14 @@ namespace Umbraco.Core.Services.Implement } } + public IMemberGroup GetById(Guid id) + { + using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + { + return _memberGroupRepository.GetMany().FirstOrDefault(x => x.Key == id); + } + } + public IMemberGroup GetByName(string name) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) diff --git a/src/Umbraco.Web/Editors/MemberGroupController.cs b/src/Umbraco.Web/Editors/MemberGroupController.cs index 67bd126e6e..ed11139e56 100644 --- a/src/Umbraco.Web/Editors/MemberGroupController.cs +++ b/src/Umbraco.Web/Editors/MemberGroupController.cs @@ -1,14 +1,18 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; 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.Models; 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; @@ -19,10 +23,29 @@ namespace Umbraco.Web.Editors /// [PluginController("UmbracoApi")] [UmbracoTreeAuthorize(Constants.Trees.MemberGroups)] + [MemberGroupControllerConfiguration] public class MemberGroupController : UmbracoAuthorizedJsonController { private readonly MembershipProvider _provider = Core.Security.MembershipProviderExtensions.GetMembersMembershipProvider(); + /// + /// Configures this controller with a custom action selector + /// + private class MemberGroupControllerConfigurationAttribute : 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 the member group json for the member group id + /// + /// + /// public MemberGroupDisplay GetById(int id) { var memberGroup = Services.MemberGroupService.GetById(id); @@ -31,8 +54,43 @@ namespace Umbraco.Web.Editors throw new HttpResponseException(HttpStatusCode.NotFound); } - var dto = Mapper.Map(memberGroup); - return dto; + return Mapper.Map(memberGroup); + } + + /// + /// Gets the member group json for the member group guid + /// + /// + /// + public MemberGroupDisplay GetById(Guid id) + { + var memberGroup = Services.MemberGroupService.GetById(id); + if (memberGroup == null) + { + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + return Mapper.Map(memberGroup); + } + + /// + /// Gets the member group json for the member group udi + /// + /// + /// + public MemberGroupDisplay GetById(Udi id) + { + var guidUdi = id as GuidUdi; + if (guidUdi == null) + throw new HttpResponseException(HttpStatusCode.NotFound); + + var memberGroup = Services.MemberGroupService.GetById(guidUdi.Guid); + if (memberGroup == null) + { + throw new HttpResponseException(HttpStatusCode.NotFound); + } + + return Mapper.Map(memberGroup); } public IEnumerable GetByIds([FromUri]int[] ids)