Example #1
0
        protected virtual void AddMyAccountMenu(CommerceHomePage homePage, CommerceHeaderViewModel viewModel)
        {
            if (HttpContext.Current != null && !HttpContext.Current.Request.IsAuthenticated)
            {
                viewModel.UserLinks = new LinkItemCollection();
                return;
            }

            var menuItems = new LinkItemCollection();
            var filter    = new FilterContentForVisitor();
            var contact   = _customerService.GetCurrentContact();

            if (contact != null && contact.FoundationOrganization != null)
            {
                var orgLink = new LinkItem
                {
                    Href  = _urlResolver.GetUrl(homePage.OrganizationMainPage),
                    Text  = _localizationService.GetString("My Organization", "My Organization"),
                    Title = _localizationService.GetString("My Organization", "My Organization")
                };
                //orgLink.Attributes.Add("css", "fa-sign-out");
                menuItems.Add(orgLink);
            }

            foreach (var linkItem in homePage.MyAccountCommerceMenu ?? new LinkItemCollection())
            {
                if (!UrlResolver.Current.TryToPermanent(linkItem.Href, out var linkUrl))
                {
                    continue;
                }

                if (linkUrl.IsNullOrEmpty())
                {
                    continue;
                }

                var urlBuilder = new UrlBuilder(linkUrl);
                var content    = _urlResolver.Route(urlBuilder);
                if (content == null || filter.ShouldFilter(content))
                {
                    continue;
                }

                linkItem.Title = linkItem.Text;
                menuItems.Add(linkItem);
            }

            var signoutText = _localizationService.GetString("/Header/Account/SignOut", "Sign Out");
            var link        = new LinkItem
            {
                Href  = "/publicapi/signout",
                Text  = signoutText,
                Title = signoutText
            };

            link.Attributes.Add("css", "fa-sign-out");
            menuItems.Add(link);

            viewModel.UserLinks.AddRange(menuItems);
        }
Example #2
0
        public LinkItemCollection FilterB2BNavigationForCurrentUser(LinkItemCollection b2BLinks)
        {
            var filteredLinks  = new LinkItemCollection();
            var currentContact = _customerService.GetCurrentContact();

            foreach (var link in b2BLinks)
            {
                switch (currentContact.B2BUserRole)
                {
                case B2BUserRoles.Admin:
                    if (Constant.B2BNavigationRoles.Admin.Contains(link.Text))
                    {
                        filteredLinks.Add(link);
                    }

                    break;

                case B2BUserRoles.Approver:
                    if (Constant.B2BNavigationRoles.Approver.Contains(link.Text))
                    {
                        filteredLinks.Add(link);
                    }

                    break;
                }
            }

            return(filteredLinks);
        }
        public virtual void AddMyAccountMenu <THomePage, THeaderViewModel>(THomePage homePage,
                                                                           THeaderViewModel viewModel)
            where THeaderViewModel : HeaderViewModel, new()
            where THomePage : CmsHomePage
        {
            if (HttpContext.Current != null && !HttpContext.Current.Request.IsAuthenticated)
            {
                viewModel.UserLinks = new LinkItemCollection();
                return;
            }

            var menuItems = new LinkItemCollection();
            var filter    = new FilterContentForVisitor();

            foreach (var linkItem in homePage.MyAccountCmsMenu ?? new LinkItemCollection())
            {
                if (!UrlResolver.Current.TryToPermanent(linkItem.Href, out var linkUrl))
                {
                    continue;
                }

                if (linkUrl.IsNullOrEmpty())
                {
                    continue;
                }

                var urlBuilder = new UrlBuilder(linkUrl);
                var content    = _urlResolver.Route(urlBuilder);
                if (content == null || filter.ShouldFilter(content))
                {
                    continue;
                }

                linkItem.Title = linkItem.Text;
                menuItems.Add(linkItem);
            }

            var signoutText = _localizationService.GetString("/Header/Account/SignOut", "Sign Out");
            var link        = new LinkItem
            {
                Href  = "/publicapi/signout",
                Text  = signoutText,
                Title = signoutText
            };

            link.Attributes.Add("css", "fa-sign-out");
            menuItems.Add(link);

            viewModel.UserLinks.AddRange(menuItems);
        }
Example #4
0
        public void AddMyAccountMenu(HomePage homePage, HeaderViewModel viewModel)
        {
            if (_httpContextAccessor.HttpContext != null && !_httpContextAccessor.HttpContext.User.Identity.IsAuthenticated)
            {
                viewModel.UserLinks = new LinkItemCollection();
                return;
            }

            var menuItems      = new LinkItemCollection();
            var filter         = new FilterContentForVisitor();
            var layoutSettings = _settingsService.GetSiteSettings <LayoutSettings>();

            foreach (var linkItem in layoutSettings.MyAccountCmsMenu ?? new LinkItemCollection())
            {
                if (!UrlResolver.Current.TryToPermanent(linkItem.Href, out var linkUrl))
                {
                    continue;
                }

                if (linkUrl.IsNullOrEmpty())
                {
                    continue;
                }

                var urlBuilder = new UrlBuilder(linkUrl);
                var content    = _urlResolver.Route(urlBuilder);
                if (content == null || filter.ShouldFilter(content))
                {
                    continue;
                }

                linkItem.Title = linkItem.Text;
                menuItems.Add(linkItem);
            }

            var signoutText = _localizationService.GetString("/Header/Account/SignOut", "Sign Out");
            var link        = new LinkItem
            {
                Href  = "/publicapi/signout",
                Text  = signoutText,
                Title = signoutText
            };

            link.Attributes.Add("css", "fa-sign-out");
            menuItems.Add(link);

            viewModel.UserLinks.AddRange(menuItems);
        }
        public void GivenInternalLink_WhenHandle_ThenReturnsCorrectAbsoluteLink()
        {
            var value = "random-internallink";
            var linkItemCollection = new LinkItemCollection();
            var expected           = "https://example.com/my-pretty-url/?anyQuery=hej";

            this._urlHelper.ContentUrl(Arg.Any <Url>(), Arg.Any <UrlSettings>())
            .Returns(expected);
            var linkItem = Substitute.For <EPiServer.SpecializedProperties.LinkItem>();

            linkItem.Href.Returns(value);
            linkItem.Text.Returns("any text");
            linkItem.Title.Returns("any title");
            linkItem.Target.Returns("_blank");
            linkItem.ReferencedPermanentLinkIds.Returns(new List <Guid>
            {
                Guid.NewGuid()
            });
            linkItemCollection.Add(linkItem);

            var result = ((IEnumerable <LinkItem>) this._sut.Handle(linkItemCollection, null, null)).ToList();

            result.Count.ShouldBe(1);
            result.ShouldContain(x => x.Href == expected);
            result.ShouldContain(x => x.Text == "any text");
            result.ShouldContain(x => x.Title == "any title");
            result.ShouldContain(x => x.Target == "_blank");
        }
        public void GivenInternalLink_WhenGetValueWithUseAbsoluteUrlsSetToFalse_ThenReturnsCorrectRelativeLink()
        {
            var value = "random-internallink";
            var linkItemCollection = new LinkItemCollection();
            var expected           = "/my-pretty-url/?anyQuery=hej";
            var settings           = new UrlSettings {
                UseAbsoluteUrls = false
            };

            this._urlHelper.ContentUrl(Arg.Any <Url>(), settings)
            .Returns(expected);
            var linkItem = Substitute.For <EPiServer.SpecializedProperties.LinkItem>();

            linkItem.Href.Returns(value);
            linkItem.Text.Returns("any text");
            linkItem.Title.Returns("any title");
            linkItem.Target.Returns("_blank");
            linkItem.ReferencedPermanentLinkIds.Returns(new List <Guid>
            {
                Guid.NewGuid()
            });
            linkItemCollection.Add(linkItem);

            var result = ((IEnumerable <LinkItem>) this._sut.GetValue(linkItemCollection, settings)).ToList();

            result.Count.ShouldBe(1);
            result.ShouldContain(x => x.Href == expected);
            result.ShouldContain(x => x.Text == "any text");
            result.ShouldContain(x => x.Title == "any title");
            result.ShouldContain(x => x.Target == "_blank");
        }
Example #7
0
        /// <summary>
        /// Renders the list.
        /// </summary>
        /// <param name="nodes">The nodes.</param>
        /// <param name="writer">The writer.</param>
        /// <param name="IsChild">if set to <c>true</c> [is child].</param>
        private void RenderList(LinkItemCollection nodes, HtmlTextWriter writer, bool IsChild, string Type)
        {
            int maxSize = this.MaxMenuSize;
            LinkItemCollection NewNodes = new LinkItemCollection();
            bool AllowEntityFiltering   = AppLogic.GlobalConfigBool("AllowEntityfiltering");

            if (AllowEntityFiltering)
            {
                foreach (ILinkItem LI in nodes)
                {
                    if (!Entity.ExistsInEntityStore(AppLogic.StoreID(), LI.ID, Type))
                    {
                    }
                    else
                    {
                        NewNodes.Add(LI);
                    }
                }
            }
            else
            {
                foreach (ILinkItem LI in nodes)
                {
                    NewNodes.Add(LI);
                }
            }

            writer.Write("<ul class=\"tame\">");
            for (int ctr = 0; ctr < NewNodes.Count; ctr++)
            {
                if (ctr == maxSize)
                {
                    break;
                }

                ProductMappingLinkItem node = NewNodes[ctr] as ProductMappingLinkItem;
                RenderItem(node, writer, IsChild);
            }
            writer.Write("</ul>");
        }
        public void GivenMailToLink_WhenHandle_ThenReturnsCorrectMailToLink()
        {
            var value = "mailto:[email protected]";
            var linkItemCollection = new LinkItemCollection();

            linkItemCollection.Add(new EPiServer.SpecializedProperties.LinkItem
            {
                Href  = value,
                Text  = "any text",
                Title = "any title"
            });

            var result = ((IEnumerable <LinkItem>) this._sut.Handle(linkItemCollection, null, null)).ToList();

            result.Count.ShouldBe(1);
            result.ShouldContain(x => x.Href == value);
            result.ShouldContain(x => x.Text == "any text");
            result.ShouldContain(x => x.Title == "any title");
        }
        public void GivenExternalLink_WhenHandle_ThenReturnsCorrectLink()
        {
            var value = "https://example.com/anypage?query=value";
            var linkItemCollection = new LinkItemCollection();

            linkItemCollection.Add(new EPiServer.SpecializedProperties.LinkItem
            {
                Href   = value,
                Text   = "any text",
                Title  = "any title",
                Target = "_blank"
            });

            var result = ((IEnumerable <LinkItem>) this._sut.Handle(linkItemCollection, null, null)).ToList();

            result.Count.ShouldBe(1);
            result.ShouldContain(x => x.Href == value);
            result.ShouldContain(x => x.Text == "any text");
            result.ShouldContain(x => x.Title == "any title");
            result.ShouldContain(x => x.Target == "_blank");
        }
 /// <summary>
 /// Gets a collection of links for all children to a given page. 
 /// It returns only visible links, which means:
 /// - not deleted
 /// - published
 /// </summary>
 /// <param name="pageLink"></param>
 /// <returns></returns>
 public static LinkItemCollection GetLinkCollectionChildren(PageReference pageLink)
 {
     LinkItemCollection result = null;
     var children = DataFactory.Instance.GetChildren(pageLink);
     if (children != null && children.Count > 0)
     {
         result = new LinkItemCollection();
         foreach (var page in children.Where(x => !x.IsDeleted && x.VisibleInMenu && x.CheckPublishedStatus(PagePublishedStatus.Published))
                 .OrderByDescending(x => x.StartPublish))
         {
             result.Add(
                 new LinkItem
                 {
                     Href = page.LinkURL,
                     Text = page.PageName,
                     Target = "",
                     Title = page.PageName,
                 });
         }
     }
     return result;
 }