Esempio n. 1
0
        /// <summary>
        /// Organises related links as headings and sections, treating a link with no URL as a heading
        /// </summary>
        /// <param name="relatedLinks">The related links.</param>
        /// <returns></returns>
        public IList <LandingSectionViewModel> OrganiseAsHeadingsAndSections(IList <HtmlLink> relatedLinks)
        {
            var groups            = new List <LandingSectionViewModel>();
            var relatedLinksGroup = new LandingSectionViewModel();

            foreach (var relatedLink in relatedLinks)
            {
                if (relatedLink.Url == null)
                {
                    if (groups.Count == 0 && relatedLinksGroup.Links == null)
                    {
                        relatedLinksGroup.Heading = relatedLink;
                    }
                    else
                    {
                        groups.Add(relatedLinksGroup);
                        relatedLinksGroup         = new LandingSectionViewModel();
                        relatedLinksGroup.Heading = relatedLink;
                    }
                }
                else
                {
                    if (relatedLinksGroup.Links == null)
                    {
                        relatedLinksGroup.Links = new List <HtmlLink>();
                    }
                    relatedLinksGroup.Links.Add(relatedLink);
                }
            }
            if (relatedLinksGroup.Links != null)
            {
                groups.Add(relatedLinksGroup);
            }
            return(groups);
        }
        /// <summary>
        /// For each related link, create a <see cref="LandingSectionViewModel" />
        /// </summary>
        /// <param name="content">The content.</param>
        /// <param name="relatedLinksService">The related links service.</param>
        /// <returns></returns>
        private static IList <LandingSectionViewModel> BuildLandingLinksViewModelFromUmbracoContent(IPublishedContent content, IRelatedLinksService relatedLinksService)
        {
            var sections = new List <LandingSectionViewModel>()
            {
            };
            var relatedLinks = relatedLinksService.BuildRelatedLinksViewModelFromUmbracoContent(content, "LandingNavigation_Content");

            foreach (var link in relatedLinks)
            {
                var section = new LandingSectionViewModel()
                {
                    Heading = link,
                    Links   = new HtmlLink[0]
                };
                sections.Add(section);
            }
            return(sections);
        }
        /// <summary>
        /// For each Umbraco Related Links property that has some data, create a <see cref="LandingSectionViewModel" /> with a heading link and list of child links.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <param name="relatedLinksService">The related links service.</param>
        /// <returns></returns>
        private static IList <LandingSectionViewModel> BuildLandingLinksViewModelFromUmbracoContent(IPublishedContent content, IRelatedLinksService relatedLinksService)
        {
            var sections = new List <LandingSectionViewModel>();

            for (var i = 1; i <= 15; i++)
            {
                var relatedLinks = relatedLinksService.BuildRelatedLinksViewModelFromUmbracoContent(content, "links" + i + "_Content");
                if (relatedLinks.Count > 0)
                {
                    var section = new LandingSectionViewModel()
                    {
                        Links = relatedLinks
                    };

                    section.Heading = section.Links[0];
                    section.Links.RemoveAt(0);

                    sections.Add(section);
                }
            }
            return(sections);
        }