/// <summary> /// Returns a collection of entities for content based on search results /// </summary> /// <param name="results"></param> /// <returns></returns> private IEnumerable <SearchResultEntity> ContentFromSearchResults(IEnumerable <ISearchResult> results) { var defaultLang = _languageService.GetDefaultLanguageIsoCode(); foreach (var result in results) { var entity = _mapper.Map <SearchResultEntity>(result); var intId = entity.Id.TryConvertTo <int>(); if (intId.Success) { //if it varies by culture, return the default language URL if (result.Values.TryGetValue(UmbracoContentIndex.VariesByCultureFieldName, out var varies) && varies == "y") { entity.AdditionalData["Url"] = _umbracoContext.Url(intId.Result, defaultLang); } else { entity.AdditionalData["Url"] = _umbracoContext.Url(intId.Result); } } yield return(entity); } }
/// <summary> /// Gets the url of an entity /// </summary> /// <param name="id">Int id of the entity to fetch URL for</param> /// <param name="type">The type of entity such as Document, Media, Member</param> /// <returns>The URL or path to the item</returns> public HttpResponseMessage GetUrl(int id, UmbracoEntityTypes type) { var returnUrl = string.Empty; if (type == UmbracoEntityTypes.Document) { var foundUrl = UmbracoContext.Url(id); if (string.IsNullOrEmpty(foundUrl) == false && foundUrl != "#") { returnUrl = foundUrl; return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(returnUrl) }); } } var ancestors = GetResultForAncestors(id, type); //if content, skip the first node for replicating NiceUrl defaults if (type == UmbracoEntityTypes.Document) { ancestors = ancestors.Skip(1); } returnUrl = "/" + string.Join("/", ancestors.Select(x => x.Name)); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(returnUrl) }); }