public async Task <ActionResult> Index() { var context = this.HttpContext; var path = context.Request.Path.Value; this.ViewBag.NewUser = context.Request.Cookies.ContainsKey("CookieDisclaimer") || this .HttpContext.Request.Cookies["CookieDisclaimer"] == "false"; var viewModel = new DynamicPageViewModel(); var alternativePaths = new string[] { "/en/path", "/fr/path" }; var pathLanguage = "EN"; if (path.Length > 3) { pathLanguage = path.Substring(1, 2); } viewModel.Language = this.SetLanguageAsThePath(pathLanguage); this.PopulateDynamicPageViewModel(viewModel, alternativePaths); viewModel.PageDataLayer = new List <KeyValuePair <string, string> >(); viewModel.Head = new Head { AlternateUrls = alternativePaths.ToList(), MetaDataTags = new List <string>(), PageHeadTags = new List <string>() }; viewModel.Content = viewModel.Language == "EN" ? "<h1>English CONTENT</h1>" : "<h1>FRENCH content</h1>"; return(View(viewModel)); }
protected void SetDefaultConfig(DynamicPageViewModel viewModel, string[] alternativePaths = null, string language = null) { viewModel.Language = viewModel.Language ?? language ?? this.UserLanguage ?? "EN"; viewModel.Country = this.UserCountry ?? "BE"; viewModel.Airport = this.UserNearestAirport ?? "BRU"; viewModel.Config = "this is the config"; viewModel.Locales = new string[] { "EN", "FR" }; viewModel.Foot = new Foot() { Config = viewModel.Config, Locales = viewModel.Locales, Language = viewModel.Language }; }
private void PopulateDynamicPageViewModel(DynamicPageViewModel viewModel, string[] alternativePaths) { this.SetDefaultConfig(viewModel, alternativePaths); viewModel.Header = new PortalHeader() { Lists = new HeaderSection[0], QuickLinks = new ExtendedLink[0] }; viewModel.Footer = new Footer(new PortalFooter { Links = new FooterSection[0] }) { Locales = viewModel.Locales }; viewModel.StaticContent = "static content"; viewModel.Footer.StaticContent = viewModel.StaticContent; }
/// <summary> /// get DynamicPage index page /// </summary> /// <param name="id"></param> /// <param name="lang"></param> /// <returns></returns> public IActionResult Index(int id, string lang) { var model = new DynamicPageViewModel(); var page = _dataAccessService.PageRoutes.Include(x => x.PageSections).FirstOrDefault(d => d.Id == id); if (page == null || !page.IsActive || page.IsDeleted || page.PageSections == null || !page.PageSections.Any(x => !x.IsDeleted && x.IsActive)) { return(View("Error")); } SetUpSEO(lang, page); ViewBag.PageTitle = lang == "en" ? page.EnName : page.ArName; //get image base url to add it to the relative url var imageBaseURL = _configuration.GetValue <string>("BackEndDomain"); //get the path that holds Dynamic Pages var dynamicPagesPath = _configuration.GetValue <string>("DynamicPagesPath"); if (page != null) { var contentFile = new FileInfo(dynamicPagesPath + (lang == "en" ? page.PageFilePathEn : page.PageFilePathAr)); string Template = contentFile.OpenText().ReadToEnd(); model.HTMLPage = Template.Replace("#baseURL#", imageBaseURL); } return(View(model)); }