public async Task <IActionResult> SyncTags() { var languages = await _cmsApiProxy.GetLanguages(); if (languages == null || !languages.Any()) { return(BadRequest("No languages found")); } var successful = await _tagRepository.DeleteIndex(); if (!successful) { _logger.LogError("Failed to delete tags index from elasticsearch."); return(BadRequest("Tags index failed to be removed.")); } foreach (var l in languages) { var tags = await _cmsApiProxy.GetTags(l.Code); if (tags == null || !tags.Any()) { continue; } var elasticTags = (await Task.WhenAll(tags.Select(MapToElasticModel))).ToList(); successful = await _tagRepository.Insert(elasticTags); if (!successful) { _logger.LogError("Failed to insert {Count} tags to elasticsearch.", elasticTags.Count); } } return(Ok()); }
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); }
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)); }
public async Task <RouteValueDictionary> GetRouteValue(RouteValueDictionary values) { var routeType = "Web"; if (values.ContainsKey("language")) { routeType = ((string)values["language"]).ToLower() == "api" ? "Api" : "Web"; } var urlPath = string.Join("/", values.Select(p => p.Value).ToArray()); _logger.LogInformation("[{RouteType}] Requested url path {UrlPath}", routeType, urlPath); string languageCode = null, regionName = null, page = null; if (values.ContainsKey("language")) { languageCode = (string)values["language"]; } if (values.ContainsKey("region")) { regionName = (string)values["region"]; } if (values.ContainsKey("page")) { page = (string)values["page"]; } if (string.IsNullOrEmpty(languageCode) && string.IsNullOrEmpty(regionName) && string.IsNullOrEmpty(page)) { values["controller"] = _defaultController; values["action"] = _defaultAction; return(values); } if (languageCode == "robots.txt") { values["controller"] = "Home"; values["action"] = "RobotsTxt"; return(values); } if (languageCode == "sitemap.xml") { values["controller"] = "Home"; values["action"] = "SitemapXml"; return(values); } var languages = _cmsApiProxy.GetLanguages()?.Result?.ToList(); if (languages != null && !languages.Any(l => l.Code == languageCode)) { page = regionName; regionName = languageCode; languageCode = null; } //var regions = _cmsApiProxy.GetRegions(languageCode)?.Result?.ToList(); var regions = _regionRepository.GetByLanguageCode(languageCode)?.Result?.ToList(); if (regions != null && !regions.Any(r => r.UrlPath == regionName)) { page = regionName; regionName = null; } var region = regions?.FirstOrDefault(r => r.UrlPath == regionName); var regionPagesUrl = region?.PagesApiPath ?? CmsVariable.DefaultPageApiPath; var regionBusinessUrl = region?.BusinessesApiPath ?? CmsVariable.DefaultBusinessApiPath; // Resolve with controller to hit based on page (string controller, int pageId) = await Resolve(languageCode, page, regionName, regions); if (controller == null) { return(values); } var regionValue = new RegionValue { Region = regionName, PagesApiUrl = regionPagesUrl, BusinessApiUrl = regionBusinessUrl }; values["controller"] = controller; values["action"] = _defaultAction; values["language"] = languageCode; values["pageId"] = pageId; values["regionValue"] = regionValue; if (controller == _errorController) { values["action"] = _notFoundAction; } return(values); }