Exemplo n.º 1
0
        protected virtual T CreateViewModel <T>(IContent currentContent, CommerceHomePage homePage, Customer.FoundationContact contact, bool isBookmarked)
            where T : CommerceHeaderViewModel, new()
        {
            var menuItems  = new List <MenuItemViewModel>();
            var menuCached = CacheManager.Get(homePage.ContentLink.ID + Constant.CacheKeys.MenuItems) as List <MenuItemViewModel>;

            if (menuCached != null)
            {
                menuItems = menuCached;
            }
            else
            {
                var menuItemBlocks = homePage.MainMenu?.FilteredItems.GetContentItems <MenuItemBlock>() ?? new List <MenuItemBlock>();
                menuItems = menuItemBlocks?
                            .Select(_ => new MenuItemViewModel
                {
                    Name       = _.Name,
                    ButtonText = _.ButtonText,
                    TeaserText = _.TeaserText,
                    Uri        = _.Link == null ? string.Empty : _urlResolver.GetUrl(new UrlBuilder(_.Link.ToString()), new UrlResolverArguments()
                    {
                        ContextMode = ContextMode.Default
                    }),
                    ImageUrl   = !ContentReference.IsNullOrEmpty(_.MenuImage) ? _urlResolver.GetUrl(_.MenuImage) : "",
                    ButtonLink = _.ButtonLink?.Host + _.ButtonLink?.PathAndQuery,
                    ChildLinks = _.ChildItems?.ToList() ?? new List <GroupLinkCollection>()
                }).ToList() ?? new List <MenuItemViewModel>();

                var keyDependency = new List <string>();
                keyDependency.Add(_contentCacheKeyCreator.CreateCommonCacheKey(homePage.ContentLink)); // If The HomePage updates menu (remove MenuItems)

                foreach (var m in menuItemBlocks)
                {
                    keyDependency.Add(_contentCacheKeyCreator.CreateCommonCacheKey((m as IContent).ContentLink));
                }

                var eviction = new CacheEvictionPolicy(TimeSpan.FromDays(1), CacheTimeoutType.Sliding, keyDependency);
                CacheManager.Insert(homePage.ContentLink.ID + Constant.CacheKeys.MenuItems, menuItems, eviction);
            }

            return(new T
            {
                HomePage = homePage,
                CurrentContentLink = currentContent?.ContentLink,
                CurrentContentGuid = currentContent?.ContentGuid ?? Guid.Empty,
                UserLinks = new LinkItemCollection(),
                Name = contact?.FirstName ?? "",
                IsBookmarked = isBookmarked,
                MenuItems = menuItems,
                LoginViewModel = new LoginViewModel
                {
                    ResetPasswordPage = homePage.ResetPasswordPage
                },
                RegisterAccountViewModel = new RegisterAccountViewModel
                {
                    Address = new AddressModel()
                },
                MobileNavigation = homePage.MobileNavigationPages,
            });
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        protected virtual void AddAnonymousComponents(CommerceHomePage homePage, CommerceHeaderViewModel viewModel)
        {
            if (HttpContext.Current != null && !HttpContext.Current.Request.IsAuthenticated)
            {
                viewModel.LoginViewModel = new LoginViewModel
                {
                    ResetPasswordPage = homePage.ResetPasswordPage
                };

                viewModel.RegisterAccountViewModel = new RegisterAccountViewModel
                {
                    Address = new AddressModel
                    {
                        CountryRegion = new CountryRegionViewModel
                        {
                            SelectClass  = "select-menu-small",
                            TextboxClass = "textbox-small"
                        }
                    }
                };

                _addressBookService.LoadAddress(viewModel.RegisterAccountViewModel.Address);
                viewModel.RegisterAccountViewModel.Address.Name = _localizationService.GetString("/Shared/Address/DefaultAddressName", "Default Address");
            }
        }
        protected override void AddMyAccountMenu(CommerceHomePage homePage, CommerceHeaderViewModel viewModel)
        {
            var demoHomePage = homePage as DemoHomePage;

            if (demoHomePage == null)
            {
                return;
            }

            if (demoHomePage.ShowCommerceHeaderComponents)
            {
                base.AddMyAccountMenu(homePage, viewModel);
                return;
            }

            viewModel.UserLinks = new LinkItemCollection();
        }
Exemplo n.º 5
0
        protected virtual T CreateViewModel <T>(IContent currentContent, CommerceHomePage homePage, Customer.FoundationContact contact, bool isBookmarked)
            where T : CommerceHeaderViewModel, new()
        {
            var menuItems    = new List <MenuItemViewModel>();
            var homeLanguage = homePage.Language.DisplayName;

            menuItems = homePage.MainMenu?.FilteredItems.Select(x =>
            {
                var itemCached = CacheManager.Get(x.ContentLink.ID + homeLanguage + ":" + Constant.CacheKeys.MenuItems) as MenuItemViewModel;
                if (itemCached != null && !PageEditing.PageIsInEditMode)
                {
                    return(itemCached);
                }
                else
                {
                    var content = _contentLoader.Get <IContent>(x.ContentLink);
                    MenuItemBlock _;
                    MenuItemViewModel menuItem;
                    if (content is MenuItemBlock)
                    {
                        _        = content as MenuItemBlock;
                        menuItem = new MenuItemViewModel
                        {
                            Name       = _.Name,
                            ButtonText = _.ButtonText,
                            TeaserText = _.TeaserText,
                            Uri        = _.Link == null ? string.Empty : _urlResolver.GetUrl(new UrlBuilder(_.Link.ToString()), new UrlResolverArguments()
                            {
                                ContextMode = ContextMode.Default
                            }),
                            ImageUrl   = !ContentReference.IsNullOrEmpty(_.MenuImage) ? _urlResolver.GetUrl(_.MenuImage) : "",
                            ButtonLink = _.ButtonLink?.Host + _.ButtonLink?.PathAndQuery,
                            ChildLinks = _.ChildItems?.ToList() ?? new List <GroupLinkCollection>()
                        };
                    }
                    else
                    {
                        menuItem = new MenuItemViewModel
                        {
                            Name       = content.Name,
                            Uri        = _urlResolver.GetUrl(content.ContentLink),
                            ChildLinks = new List <GroupLinkCollection>()
                        };
                    }

                    if (!PageEditing.PageIsInEditMode)
                    {
                        var keyDependency = new List <string>();
                        keyDependency.Add(_contentCacheKeyCreator.CreateCommonCacheKey(homePage.ContentLink)); // If The HomePage updates menu (remove MenuItems)
                        keyDependency.Add(_contentCacheKeyCreator.CreateCommonCacheKey(x.ContentLink));

                        var eviction = new CacheEvictionPolicy(TimeSpan.FromDays(1), CacheTimeoutType.Sliding, keyDependency);
                        CacheManager.Insert(x.ContentLink.ID + homeLanguage + ":" + Constant.CacheKeys.MenuItems, menuItem, eviction);
                    }

                    return(menuItem);
                }
            }).ToList();

            return(new T
            {
                HomePage = homePage,
                CurrentContentLink = currentContent?.ContentLink,
                CurrentContentGuid = currentContent?.ContentGuid ?? Guid.Empty,
                UserLinks = new LinkItemCollection(),
                Name = contact?.FirstName ?? "",
                IsBookmarked = isBookmarked,
                IsReadonlyMode = _databaseMode.DatabaseMode == DatabaseMode.ReadOnly,
                MenuItems = menuItems ?? new List <MenuItemViewModel>(),
                LoginViewModel = new LoginViewModel
                {
                    ResetPasswordPage = homePage.ResetPasswordPage
                },
                RegisterAccountViewModel = new RegisterAccountViewModel
                {
                    Address = new AddressModel()
                },
            });
        }