private static UrlMappingResult <Entity> GetResultFromQuery(IEnumerable <Entity> query) { // select only root pages or pages where isroot = null var duplicateCheckArray = query.Where(p => p.GetAttributeValue <bool?>("adx_isroot") != false).ToArray(); var result = query.FirstOrDefault(); return(duplicateCheckArray.Length > 1 ? UrlMappingResult <Entity> .DuplicateResult(result) : UrlMappingResult <Entity> .MatchResult(result)); }
private static UrlMappingResult <WebPageNode> FilterResultsOnLanguage(IEnumerable <WebPageNode> pages, Func <WebPageNode, bool> predicate, WebPageLookupOptions lookupOption, ContextLanguageInfo contextLanguageInfo) { var results = pages.Where(predicate); WebPageNode retval = null; if (contextLanguageInfo != null && contextLanguageInfo.IsCrmMultiLanguageEnabled) { if (lookupOption == WebPageLookupOptions.LanguageContentOnly) { // when we have only a root webpage and 0 localized webpages. // for example: creating new child page via portal CMS. if (results.Where(p => p.IsRoot == false).Count() == 0) { retval = results.FirstOrDefault(); } else { var websiteLanguageId = contextLanguageInfo.ContextLanguage.EntityReference.Id; retval = results.FirstOrDefault(p => p.WebPageLanguage != null && p.WebPageLanguage.Id == websiteLanguageId && p.IsRoot == false); } } else if (lookupOption == WebPageLookupOptions.RootOnly) { retval = results.FirstOrDefault(p => p.IsRoot == true); } else { retval = results.FirstOrDefault(); } // If the found page is content, but the root page is deactivated, then return null as if the page itself doesn't exist. if (retval != null && retval.IsRoot == false && (retval.RootWebPage == null || retval.RootWebPage.IsReference)) { retval = null; } } else { // If multi-language is not supported, then do legacy behavior of returning first result. retval = results.FirstOrDefault(); } // select only root pages or pages where isroot = null (MLP is not supported) var duplicateCheckArray = results.Where(p => p.IsRoot != false).ToArray(); return(duplicateCheckArray.Length > 1 ? UrlMappingResult <WebPageNode> .DuplicateResult(retval) : UrlMappingResult <WebPageNode> .MatchResult(retval)); }