public async Task <IActionResult> PageUpdate([FromBody] CmsPostWebHookApiModel model)
        {
            if (model == null)
            {
                return(BadRequest("delete model empty or null."));
            }

            var postId = model.post_id;

            if (postId <= 0)
            {
                return(BadRequest($"post id null. model.post_id: {postId}"));
            }

            var webHookTypeName = HeaderType();

            if (string.IsNullOrEmpty(webHookTypeName) || webHookTypeName != "post_update")
            {
                return(BadRequest("no webhook name provided."));
            }

            var apiPath = model.post.post_type;

            _cmsApiProxy.RemovePageCache(postId);
            _cmsApiProxy.RemovePagesCache(apiPath);

            await _cmsApiProxy.GetPage(postId, apiPath);

            await _cmsApiProxy.GetPages(regionPageApiPath : apiPath);

            _logger.LogInformation("Cleared and renewed cache for page {PageId} for page api path {ApiPath}.", postId, apiPath);

            return(Ok());
        }
Esempio n. 2
0
        private async Task <(string controller, int pageId)> Resolve(
            string language,
            string routePage,
            string routeRegion,
            List <RegionElasticModel> regions)
        {
            if (string.IsNullOrEmpty(routePage))
            {
                return(_defaultController, -1);
            }

            var normalizedPage = routePage.ToLowerInvariant();

            var activeRegion   = regions?.FirstOrDefault(r => r.UrlPath == routeRegion);
            var regionPagesUrl = activeRegion?.PagesApiPath ?? CmsVariable.DefaultPageApiPath;

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

            var page       = pages.FirstOrDefault(p => p.Slug == normalizedPage);
            var controller = page?.Page_type?.FirstOrDefault()?.Template_name;
            var pageId     = page?.Id ?? -1;

            if (controller == null)
            {
                var businessPagePartialUrl = $"/{normalizedPage}";
                var languageCode           = string.IsNullOrEmpty(language) ? CmsVariable.DefaultLanguageCode : language;
                var businesses             = await BusinessRepository.GetBusinesses(randomSeed : 0, from : 0, size : CmsVariable.ElasticSize, languageCode : languageCode);

                var business = businesses?.Items?.FirstOrDefault(b => b.Business.DetailPageLink.EndsWith(businessPagePartialUrl));
                if (business?.Business != null)
                {
                    _logger.LogInformation("Found business from {PageUrl} with language code {LanguageCode} and region {RouteRegion}. Business language code {BusinessLanguageCode}, city id:{Region}, url:{Url}.",
                                           businessPagePartialUrl, languageCode, routeRegion, business.Business.LanguageCode, business.Business.City.Name, business.Business.DetailPageLink);
                    pageId = business.Business.Id;
                    var templateName = business.Business.PageType?.Name;

                    if (!string.IsNullOrEmpty(templateName))
                    {
                        controller = templateName;
                    }
                }
            }

            if (controller == null)
            {
                controller = _errorController;
            }

            return(controller, pageId);
        }
Esempio n. 3
0
        private async Task <UrlViewModel> GetSiteMapXml(string host)
        {
            var model = new UrlViewModel();
            // from here if disabled /*
            var regions = await _regionRepository.GetAll();

            var languages = await _cmsApiProxy.GetLanguages();

            var defaultLanguage = languages.FirstOrDefault(x => x.Default)?.Code;

            foreach (var region in regions.OrderBy(x => x.MenuOrder))
            {
                var languageCode   = region.LanguageCode;
                var langUrl        = GetLanguageUrl(languageCode, defaultLanguage);
                var regionPagesUrl = region.PagesApiPath ?? CmsVariable.DefaultPageApiPath;
                var pages          = await _cmsApiProxy.GetPages(languageCode, regionPagesUrl);

                var regionSlug = string.IsNullOrEmpty(region.UrlPath) || region.UrlPath == CmsVariable.GlobalUrlPath ? "" : $"/{region.UrlPath}";

                model.Urls.Add(new UrlViewModel.UrlItem {
                    Url = $"{host}{langUrl}{regionSlug}", LastUpdated = region.Modified
                });

                foreach (var page in pages)
                {
                    var lastUpdated = page.Modified;
                    var url         = $"{host}{langUrl}{regionSlug}/{page.Slug}";

                    model.Urls.Add(new UrlViewModel.UrlItem {
                        Url = url, LastUpdated = lastUpdated
                    });
                }
            }

            var allBusinesses = await _businessRepository.GetAll();

            foreach (var business in allBusinesses)
            {
                var lastUpdated = business.LastUpdated.ToString(); // "yyyy-MM-dd"
                var url         = $"{host}{business.DetailPageLink}";

                model.Urls.Add(new UrlViewModel.UrlItem {
                    Url = url, LastUpdated = lastUpdated
                });
            }
            // to here if disabled */
            return(model);
        }
Esempio n. 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, 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));
        }
Esempio n. 5
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));
        }