Пример #1
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var language = RouteData?.Values["language"]?.ToString();

            var regionValue = RouteData?.Values["regionValue"] as RegionValue;
            var region      = regionValue?.Region;

            var(regionPagesUrl, _, regionTitle, regions) = await _cmsApiProxy.GetRegionList(region, language);

            var baseUrl = $"/{language}";

            var model = new TopBarViewModel
            {
                Regions = regions.Select(n => new TopBarViewModel.RegionViewModel
                {
                    Id      = n.Id,
                    Name    = n.Title?.Rendered,
                    UrlPath = GetRegionUrlPath(language, n.Url_path)
                }).ToList(),
                Region         = regionTitle,
                LanguageCode   = language,
                BasePartialUrl = baseUrl
            };

            var pages = await _cmsApiProxy.GetPages(language, regionPagesUrl);

            var urlList    = new List <string>();
            var partialUrl = string.Empty;

            if (!string.IsNullOrEmpty(language))
            {
                urlList.Add(language);
            }

            if (!string.IsNullOrEmpty(region))
            {
                urlList.Add(region);
            }

            if (urlList.Any())
            {
                partialUrl = string.Join("/", urlList);
            }

            model.RegionUrl = $"/{partialUrl}";

            // Get only top menu pages
            model.Pages = pages
                          .Where(p => p.Page_type?.First().TypeName == CmsVariable.TopMenuPageTypeName)
                          .Select(n => new TopBarViewModel.PageViewModel
            {
                Id       = n.Id,
                PageName = n.Title?.Rendered,
                UrlPath  = !string.IsNullOrEmpty(partialUrl) ? $"{partialUrl}/{n.Slug}" : n.Slug
            }).ToList();

            model.RootUrl = $"{Request.Scheme}://{Request.Host}";

            model.Translations = await _cmsApiProxy.GetTranslationsByPrefix(language, "topbar.");

            return(View(model));
        }
Пример #2
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var language = RouteData?.Values["language"]?.ToString();

            var regionValue = RouteData?.Values["regionValue"] as RegionValue;
            var region      = regionValue?.Region;

            var(regionPagesUrl, _, regionTitle, _) = await _cmsApiProxy.GetRegionList(region, language);

            var globalPages = await _cmsApiProxy.GetPages(language);

            var urlList    = new List <string>();
            var partialUrl = string.Empty;

            if (!string.IsNullOrEmpty(language))
            {
                urlList.Add(language);
            }

            if (urlList.Any())
            {
                partialUrl = string.Join("/", urlList);
            }

            var leftFooterPages   = GetPages(globalPages, CmsPageType.LeftFooter, partialUrl);
            var centerFooterPages = GetPages(globalPages, CmsPageType.CenterFooter, partialUrl);
            var rightFooterPages  = GetPages(globalPages, CmsPageType.RightFooter, partialUrl);

            if (regionPagesUrl != CmsVariable.DefaultPageApiPath && false == true)
            {
                urlList = new List <string>();

                if (!string.IsNullOrEmpty(language))
                {
                    urlList.Add(language);
                }

                if (!string.IsNullOrEmpty(region))
                {
                    urlList.Add(region);
                }

                if (urlList.Any())
                {
                    partialUrl = string.Join("/", urlList);
                }

                var pages = await _cmsApiProxy.GetPages(language, regionPagesUrl);

                leftFooterPages = GetPages(pages, CmsPageType.LeftFooter, partialUrl);
            }

            var translations = await _cmsApiProxy.GetTranslationsByPrefix(language, "footer.");

            var model = new FooterViewModel
            {
                Translations = translations,
                Header       = translations["footer.center-title"],
                RegionTitle  = CmsVariable.SiteName,
//                Header = regionTitle == "" ? translations["footer.center-title"] : CmsVariable.SiteName,
//                RegionTitle = regionTitle == "" ? CmsVariable.SiteName : regionTitle,
                LeftFooterPages   = leftFooterPages,
                CenterFooterPages = centerFooterPages,
                RightFooterPages  = rightFooterPages,
                Languages         = new List <FooterViewModel.LanguageViewModel>()
            };

            // TODO: Keep current route (region, page) when switching language?
            var languages = await _cmsApiProxy.GetLanguages();

            foreach (var l in languages)
            {
                model.Languages.Add(l.Default
                    ? new FooterViewModel.LanguageViewModel("/", l.Name)
                    : new FooterViewModel.LanguageViewModel($"/{l.Code}/", l.Name));
            }

            return(View(model));
        }