/// <summary>
        /// Renders page link.
        /// </summary>
        /// <param name="htmlHelper">This is an HtmlHelper extension method.</param>
        /// <param name="pageLinkViewModel">Contains all of the information required to render a page link.</param>
        /// <returns>MvcHtmlString containing page link.</returns>
        public static IHtmlContent PageLink(this IHtmlHelper htmlHelper, PageLinkViewModel pageLink)
        {
            // If page ID not specified, then render link to the current page (this might be the case on a special administration page, where PageId is not set)
            if (pageLink.Page.PageId == 0)
            {
                string pathAndQuery = string.Format("{0}{1}", htmlHelper.ViewContext.HttpContext.Request.Path, htmlHelper.ViewContext.HttpContext.Request.QueryString);
                string pageLinkHtml = string.Format("<a href=\"{0}\">{1}</a>", pathAndQuery, htmlHelper.Encode(pageLink.LinkText));
                return(new HtmlString(pageLinkHtml));
            }

            // Otherwise, render link to page specified
            if (pageLink.Page.ParentPageId == null)
            {
                return(htmlHelper.RouteLink(pageLink.LinkText, "HomePage", pageLink.RouteValues, pageLink.HtmlAttributes));
            }
            else
            {
                IWebHelperService    webHelperService         = (IWebHelperService)htmlHelper.ViewContext.HttpContext.RequestServices.GetService(typeof(IWebHelperService));
                RouteValueDictionary routeValueDictionary     = pageLink.RouteValues == null ? new RouteValueDictionary() : new RouteValueDictionary(pageLink.RouteValues);
                RouteValueDictionary htmlAttributesDictionary = pageLink.HtmlAttributes == null ? new RouteValueDictionary() : new RouteValueDictionary(pageLink.HtmlAttributes);
                routeValueDictionary.Add("pageid", pageLink.Page.PageId);
                routeValueDictionary.Add("description", webHelperService.UrlFriendly(pageLink.Description));
                return(htmlHelper.RouteLink(pageLink.LinkText, "ReadPage", routeValueDictionary, (IDictionary <string, object>)htmlAttributesDictionary));
            }
        }
        /// <summary>
        /// Renders a page URL with route values.
        /// </summary>
        /// <param name="urlHelper">This is a UrlHelper extension method.</param>
        /// <param name="page">The page whose link is rendered.</param>
        /// <param name="description">SEO text that is displayed just before query string.</param>
        /// <param name="routeValues">Route values that should be added to the link.</param>
        /// <returns>String containing page URL.</returns>
        public static string PageUrl(this IUrlHelper urlHelper, Page page, string description, object routeValues)
        {
            IWebHelperService    webHelperService     = (IWebHelperService)urlHelper.ActionContext.HttpContext.RequestServices.GetService(typeof(IWebHelperService));
            RouteValueDictionary routeValueDictionary = routeValues == null ? new RouteValueDictionary() : new RouteValueDictionary(routeValues);

            routeValueDictionary.Add("pageid", page.PageId);
            routeValueDictionary.Add("description", webHelperService.UrlFriendly(description));
            return(urlHelper.RouteUrl("ReadPage", routeValueDictionary));
        }
 /// <summary>
 /// Makes keyword substitutions on layout text.
 /// </summary>
 /// <param name="page">Page information.</param>
 /// <param name="text">Text.</param>
 /// <returns>Text with keywords replaced with dynamic content.</returns>
 private string FormatLayoutHtml(Page page, string text)
 {
     if (page.PreviewImageUploadId.HasValue && text != null && text.Contains("class=\"jumbotron-outer\""))
     {
         string url         = _webHelperService.RouteUrl("ReadPageImage", new { pageid = page.PageId, format = "preview", description = _webHelperService.UrlFriendly(page.Name), t = page.PreviewImageUploadId });
         string replaceText = string.Format("class=\"jumbotron-outer\" style=\"background-image: url({0});\"", url);
         text = text.Replace("class=\"jumbotron-outer\"", replaceText);
     }
     return(text);
 }
        public static string UrlFriendly(this IUrlHelper urlHelper, string text)
        {
            IWebHelperService webHelperService = (IWebHelperService)urlHelper.ActionContext.HttpContext.RequestServices.GetService(typeof(IWebHelperService));

            return(webHelperService.UrlFriendly(text));
        }