From fc5bf81991fa79f10fd8753da22de8bec7f3abf6 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Wed, 18 Jan 2017 12:33:43 +0000 Subject: [PATCH] Returns a string as opposed to a Dynamic object - however cannot return a string object from this method as the result is wrapped in quotes hence we use a HttpResponseMessage & StringContent to return a raw string from the API endpoint --- src/Umbraco.Web/Editors/EntityController.cs | 31 ++++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs index cfc04a7f20..9f8b15449c 100644 --- a/src/Umbraco.Web/Editors/EntityController.cs +++ b/src/Umbraco.Web/Editors/EntityController.cs @@ -17,6 +17,7 @@ using Umbraco.Core.Services; using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Mvc; using System.Linq; +using System.Net.Http; using Umbraco.Core.Models.EntityBase; using Umbraco.Core.Models; using Umbraco.Web.WebApi.Filters; @@ -146,19 +147,27 @@ namespace Umbraco.Web.Editors - - public dynamic GetUrl(int id, UmbracoEntityTypes type) + /// + /// Gets the url of an entity + /// + /// Int id of the entity to fetch URL for + /// The tpye of entity such as Document, Media, Member + /// The URL or path to the item + public HttpResponseMessage GetUrl(int id, UmbracoEntityTypes type) { - dynamic result = new System.Dynamic.ExpandoObject(); - + var returnUrl = string.Empty; - if(type == UmbracoEntityTypes.Document) + if (type == UmbracoEntityTypes.Document) { var foundUrl = Umbraco.Url(id); if (string.IsNullOrEmpty(foundUrl) == false && foundUrl != "#") { - result.url = foundUrl; - return result; + returnUrl = foundUrl; + + return new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent(returnUrl) + }; } } @@ -169,10 +178,12 @@ namespace Umbraco.Web.Editors ancestors = ancestors.Skip(1); } - result.url = "/" + string.Join("/", ancestors.Select(x => x.Name) ); + returnUrl = "/" + string.Join("/", ancestors.Select(x => x.Name)); - - return result; + return new HttpResponseMessage(HttpStatusCode.OK) + { + Content = new StringContent(returnUrl) + }; } ///