public async Task <IViewComponentResult> InvokeAsync()
        {
            var language = RouteData?.Values["language"]?.ToString();
            var show     = !(HttpContext.Request.Cookies["cookieconsent"] != null && HttpContext.Request.Cookies["cookieconsent"] == "1");

            var model = new CookieConsentViewModel
            {
                Translations      = await _cmsApiProxy.GetTranslationsByPrefix(language, "cookieconsent."),
                Context           = HttpContext,
                ShowCookieConsent = show
            };

            return(View(model));
        }
        public async Task <IActionResult> Index()
        {
            var page = await _businessRepository.Get(_pageId);

            if (page == null)
            {
                _logger.LogWarning($"Page not found. Business with id:{_pageId} not found in elastic.");
                return(View(new BusinessPageViewModel
                {
                    Header = "Not Found"
                }));
            }

            var requestPath = Request?.Path.ToString();

            if (requestPath != null && !requestPath.StartsWith(page.DetailPageLink))
            {
                // 302 Redirect
                return(Redirect(page.DetailPageLink));
            }

            var addressAndCoordinates = page.AddressAndCoordinates?
                                        .Select(x => new BusinessPageViewModel.AddressAndCoordinateModel
            {
                Address   = x.Address,
                Latitude  = x.Latitude,
                Longitude = x.Longitude
            }).ToList();

            var addressAndCoordinatesJson = JsonConvert.SerializeObject(addressAndCoordinates)?.ToLower();

            var language     = RouteData?.Values["language"]?.ToString();
            var translations = await _cmsApiProxy.GetTranslationsByPrefix(language, "businesspage.");

            var htmlDescription = StringHelper.SanitizeHtml(page.Description, _cmsDomain);
            var model           = new BusinessPageViewModel
            {
                Translations              = translations,
                Header                    = page.Header,
                ShortDescription          = page.ShortDescription,
                Description               = htmlDescription,
                City                      = page.City.Name,
                Area                      = page.Area,
                Email                     = page.Email,
                OnlineOnly                = page.OnlineOnly ?? false,
                FacebookUrl               = page.FacebookUrl,
                WebsiteUrl                = page.WebsiteUrl,
                InstagramUsername         = page.InstagramUsername,
                PhoneFormatted            = StringHelper.FormatPhone(page.Phone),
                Phone                     = page.Phone,
                Tags                      = page.Tags,
                AddressAndCoordinatesJson = addressAndCoordinatesJson,
                AddressAndCoordinates     = addressAndCoordinates,
                HasImage                  = page.Image?.ImageId != null,
                Image                     = new BusinessPageViewModel.ImageModel
                {
                    ImageUrl = page.Image?.Large?.Url,
                    AltText  = page.Image?.AltText,
                    ImageId  = page.Image?.ImageId
                },
                OpeningHours = new BusinessPageViewModel.OpeningHoursModel
                {
                    AlwaysOpen          = page.OpeningHours?.AlwaysOpen ?? false,
                    HideOpeningHours    = page.OpeningHours?.HideOpeningHours ?? false,
                    TextForOpeningHours = page.OpeningHours?.TextForOpeningHours,
                },
                Ogp = new OgpViewModel
                {
                    Title       = page.Header,
                    Description = page.ShortDescription,
                    Type        = "article",
                    ImageUrl    = page.Image?.Large?.Url,
                    ImageHeight = page.Image?.Large?.Height,
                    ImageWidth  = page.Image?.Large?.Width,
                    Url         = Request.GetDisplayUrl()
                }
            };

            var closedTranslation = translations["businesspage.closed"];

            model.OpeningHours.Days = new List <BusinessPageViewModel.DayInfoModel>();
            model.OpeningHours.Days.Add(new BusinessPageViewModel.DayInfoModel
            {
                DayText     = translations["businesspage.monday"],
                Closed      = page.OpeningHours?.ClosedOnMonday ?? false,
                OpeningHour = FormatTime(page.OpeningHours?.OpeningHourMonday),
                ClosingHour = FormatTime(page.OpeningHours?.ClosingHourMonday),
                HoursText   = (page.OpeningHours?.ClosedOnMonday ?? false)
                    ? closedTranslation
                    : $"{FormatTime(page.OpeningHours?.OpeningHourMonday)} - {FormatTime(page.OpeningHours?.ClosingHourMonday)}"
            });
            model.OpeningHours.Days.Add(new BusinessPageViewModel.DayInfoModel
            {
                DayText     = translations["businesspage.tuesday"],
                Closed      = page.OpeningHours?.ClosedOnTuesday ?? false,
                OpeningHour = FormatTime(page.OpeningHours?.OpeningHourTuesday),
                ClosingHour = FormatTime(page.OpeningHours?.ClosingHourTuesday),
                HoursText   = (page.OpeningHours?.ClosedOnTuesday ?? false)
                    ? closedTranslation
                    : $"{FormatTime(page.OpeningHours?.OpeningHourTuesday)} - {FormatTime(page.OpeningHours?.ClosingHourTuesday)}"
            });
            model.OpeningHours.Days.Add(new BusinessPageViewModel.DayInfoModel
            {
                DayText     = translations["businesspage.wednesday"],
                Closed      = page.OpeningHours?.ClosedOnWednesday ?? false,
                OpeningHour = FormatTime(page.OpeningHours?.OpeningHourWednesday),
                ClosingHour = FormatTime(page.OpeningHours?.ClosingHourWednesday),
                HoursText   = (page.OpeningHours?.ClosedOnWednesday ?? false)
                    ? closedTranslation
                    : $"{FormatTime(page.OpeningHours?.OpeningHourWednesday)} - {FormatTime(page.OpeningHours?.ClosingHourWednesday)}"
            });
            model.OpeningHours.Days.Add(new BusinessPageViewModel.DayInfoModel
            {
                DayText     = translations["businesspage.thursday"],
                Closed      = page.OpeningHours?.ClosedOnThursday ?? false,
                OpeningHour = FormatTime(page.OpeningHours?.OpeningHourThursday),
                ClosingHour = FormatTime(page.OpeningHours?.ClosingHourThursday),
                HoursText   = (page.OpeningHours?.ClosedOnThursday ?? false)
                    ? closedTranslation
                    : $"{FormatTime(page.OpeningHours?.OpeningHourThursday)} - {FormatTime(page.OpeningHours?.ClosingHourThursday)}"
            });
            model.OpeningHours.Days.Add(new BusinessPageViewModel.DayInfoModel
            {
                DayText     = translations["businesspage.friday"],
                Closed      = page.OpeningHours?.ClosedOnFriday ?? false,
                OpeningHour = FormatTime(page.OpeningHours?.OpeningHourFriday),
                ClosingHour = FormatTime(page.OpeningHours?.ClosingHourFriday),
                HoursText   = (page.OpeningHours?.ClosedOnFriday ?? false)
                    ? closedTranslation
                    : $"{FormatTime(page.OpeningHours?.OpeningHourFriday)} - {FormatTime(page.OpeningHours?.ClosingHourFriday)}"
            });
            model.OpeningHours.Days.Add(new BusinessPageViewModel.DayInfoModel
            {
                DayText     = translations["businesspage.saturday"],
                Closed      = page.OpeningHours?.ClosedOnSaturday ?? false,
                OpeningHour = FormatTime(page.OpeningHours?.OpeningHourSaturday),
                ClosingHour = FormatTime(page.OpeningHours?.ClosingHourSaturday),
                HoursText   = (page.OpeningHours?.ClosedOnSaturday ?? false)
                    ? closedTranslation
                    : $"{FormatTime(page.OpeningHours?.OpeningHourSaturday)} - {FormatTime(page.OpeningHours?.ClosingHourSaturday)}"
            });
            model.OpeningHours.Days.Add(new BusinessPageViewModel.DayInfoModel
            {
                DayText     = translations["businesspage.sunday"],
                Closed      = page.OpeningHours?.ClosedOnSunday ?? false,
                OpeningHour = FormatTime(page.OpeningHours?.OpeningHourSunday),
                ClosingHour = FormatTime(page.OpeningHours?.ClosingHourSunday),
                HoursText   = (page.OpeningHours?.ClosedOnSunday ?? false)
                    ? closedTranslation
                    : $"{FormatTime(page.OpeningHours?.OpeningHourSunday)} - {FormatTime(page.OpeningHours?.ClosingHourSunday)}"
            });

            return(View(model));
        }
示例#3
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));
        }
示例#4
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));
        }