public ActionResult CmsPagesLanguages(List <BackEndCmsPagesLanguagesAddEdit> backEndCmsPagesLanguagesAddEditList, int id)
        {
            PagesLanguages backEndCmsPagesLanguages = new PagesLanguages();
            int?           result;
            bool           isLoopSuccessful = true;

            foreach (BackEndCmsPagesLanguagesAddEdit backEndCmsPagesLanguagesAddEdit in backEndCmsPagesLanguagesAddEditList)
            {
                result = backEndCmsPagesLanguages.AddEdit(id, backEndCmsPagesLanguagesAddEdit.LanguageCode, backEndCmsPagesLanguagesAddEdit.MenuName, backEndCmsPagesLanguagesAddEdit.MetaTagTitle, backEndCmsPagesLanguagesAddEdit.MetaTagKeywords, backEndCmsPagesLanguagesAddEdit.MetaTagDescription, backEndCmsPagesLanguagesAddEdit.Robots, backEndCmsPagesLanguagesAddEdit.HtmlCode);
                switch (result)
                {
                case 0:
                    //success
                    break;

                default:
                    isLoopSuccessful = false;
                    ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.UnexpectedError);
                    break;
                }
                if (!isLoopSuccessful)
                {
                    break;
                }
            }
            if (isLoopSuccessful)
            {
                ModelState.AddResult(ViewData, ModelStateResult.Success, Resources.Strings.ItemSuccessfullyEdited);
            }

            return(View(backEndCmsPagesLanguagesAddEditList));
        }
Example #2
0
        public ActionResult CmsPagesDelete(int deleteId)
        {
            CmsPages CmsPages = new CmsPages();

            switch (CmsPages.Delete(deleteId))
            {
            case 0:
                PagesLanguages pagesLanguages = new PagesLanguages();
                pagesLanguages.ForceCache();

                ModelState.AddResult(ViewData, ModelStateResult.Success, Resources.Strings.ItemSuccessfullyDeleted);
                break;

            case 2:
                ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.ItemDoesNotExist);
                break;

            case 3:
                ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.PageHasSubPages);
                break;

            default:
                ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.UnexpectedError);
                break;
            }

            return(RedirectToAction("CmsPages"));
        }
Example #3
0
        public ActionResult FileManagerIsFileUsed(string f)
        {
            bool isFileUsed = false;

            if (!isFileUsed)
            {
                PagesLanguages backEndCmsPagesContent = new PagesLanguages();
                isFileUsed = backEndCmsPagesContent.IsFileUsed(f);
            }

            if (!isFileUsed)
            {
                PageTemplates backEndCmsPagesTemplates = new PageTemplates();
                isFileUsed = backEndCmsPagesTemplates.IsFileUsed(f);
            }

            if (!isFileUsed)
            {
                foreach (IModuleConnector moduleConnector in ModuleConnectorsHelper.GetModuleConnectors())
                {
                    isFileUsed = moduleConnector.IsFileUsed(f);
                    if (isFileUsed)
                    {
                        break;
                    }
                }
            }

            return(Content(isFileUsed.ToString(), "text/plain"));
        }
Example #4
0
        public static IHtmlString GetSitemap(this HtmlHelper htmlHelper, FrontEndCmsPage model, string className = "")
        {
            string         sitemap = string.Empty;
            PagesLanguages backEndCmsPagesLanguages = new PagesLanguages();

            BuildSitemap(new CmsPages().GetAllPages(), backEndCmsPagesLanguages, 1, null, ref sitemap, className, model.LanguageCode);
            return(htmlHelper.Raw(sitemap));
        }
        public static IHtmlString GetFooterMenu(this HtmlHelper htmlHelper, FrontEndCmsPage model, string className = "nav nav-pills")
        {
            string         footerMenu = string.Empty;
            List <CmsPage> pagesObj   = new CmsPages().GetAllPages();

            if (pagesObj != null)
            {
                pagesObj = (from page in pagesObj
                            where page.ShowInBottomMenu && page.IsActive
                            select page).ToList();
                if (pagesObj != null && pagesObj.Count > 0)
                {
                    footerMenu += "<ul class=\"" + className + "\">";
                    string url;
                    GlobalConfiguration globalConfiguration    = new GlobalConfigurations().GetGlobalConfiguration();
                    PagesLanguages      backEndCmsPagesContent = new PagesLanguages();
                    PageLanguage        backEndCmsPageLanguage;
                    string pageTitle = string.Empty;
                    foreach (CmsPage pageObj in pagesObj)
                    {
                        backEndCmsPageLanguage = backEndCmsPagesContent.GetPageLanguage(pageObj.PageId, model.LanguageCode);

                        if (backEndCmsPageLanguage.IsNotNull() && backEndCmsPageLanguage.MenuName.IsNotEmptyOrWhiteSpace())
                        {
                            pageTitle = backEndCmsPageLanguage.MenuName;
                        }
                        else
                        {
                            pageTitle = pageObj.PageName;
                        }

                        if (pageObj.PageTemplateId.IsNull())
                        {
                            url = pageObj.Url;
                        }
                        else
                        {
                            url = "/";
                            if (!pageObj.IsHomePage || model.LanguageCode != globalConfiguration.DefaultLanguageCode)
                            {
                                if (pageObj.IsHomePage)
                                {
                                    url += model.LanguageCode + "/";
                                }
                                else
                                {
                                    url += model.LanguageCode + "/" + pageObj.FullSegment + "/";
                                }
                            }
                        }
                        footerMenu += "<li><a href=\"" + url + "\" target=\"" + pageObj.Target + "\" title=\"" + pageTitle + "\">" + pageTitle + "</a></li>";
                    }
                    footerMenu += "</ul>";
                }
            }
            return(htmlHelper.Raw(footerMenu));
        }
        public ActionResult CmsPagesLanguages(int id)
        {
            List <BackEndCmsPagesLanguagesAddEdit> backEndCmsPagesLanguagesAddEditList = new List <BackEndCmsPagesLanguagesAddEdit>();

            CmsPages CmsPages = new CmsPages();
            CmsPage  CmsPage;
            BackEndCmsPagesLanguagesAddEdit backEndCmsPagesLanguagesAddEdit;
            PagesLanguages backEndCmsPagesLanguages = new PagesLanguages();
            PageLanguage   backEndCmsPageLanguage;

            foreach (Language language in new Languages().GetAllLanguages(isActive: true))
            {
                backEndCmsPagesLanguagesAddEdit = new BackEndCmsPagesLanguagesAddEdit();
                CmsPage = CmsPages.GetPageByPageId(id);
                if (CmsPage.IsNotNull())
                {
                    backEndCmsPagesLanguagesAddEdit.PageId       = CmsPage.PageId;
                    backEndCmsPagesLanguagesAddEdit.LanguageCode = language.LanguageCode;
                    backEndCmsPagesLanguagesAddEdit.PageName     = CmsPage.PageName;
                    backEndCmsPagesLanguagesAddEdit.LanguageName = language.LanguageName;

                    backEndCmsPageLanguage = backEndCmsPagesLanguages.GetPageLanguage(CmsPage.PageId, language.LanguageCode);
                    if (backEndCmsPageLanguage.IsNotNull())
                    {
                        backEndCmsPagesLanguagesAddEdit.MenuName           = backEndCmsPageLanguage.MenuName;
                        backEndCmsPagesLanguagesAddEdit.MetaTagTitle       = backEndCmsPageLanguage.MetaTagTitle;
                        backEndCmsPagesLanguagesAddEdit.MetaTagKeywords    = backEndCmsPageLanguage.MetaTagKeywords;
                        backEndCmsPagesLanguagesAddEdit.MetaTagDescription = backEndCmsPageLanguage.MetaTagDescription;
                        backEndCmsPagesLanguagesAddEdit.Robots             = backEndCmsPageLanguage.Robots;
                        backEndCmsPagesLanguagesAddEdit.HtmlCode           = backEndCmsPageLanguage.HtmlCode;
                    }
                    else
                    {
                        backEndCmsPagesLanguages.AddEdit(id, backEndCmsPagesLanguagesAddEdit.LanguageCode, CmsPage.PageName, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);
                        backEndCmsPageLanguage = backEndCmsPagesLanguages.GetPageLanguage(CmsPage.PageId, language.LanguageCode);
                    }
                }
                else
                {
                    ModelState.AddResult(ViewData, ModelStateResult.Error, Resources.Strings.ItemDoesNotExist);
                    ViewData.IsFormVisible(false);
                    break;
                }
                backEndCmsPagesLanguagesAddEditList.Add(backEndCmsPagesLanguagesAddEdit);
            }

            return(View(backEndCmsPagesLanguagesAddEditList));
        }
Example #7
0
        public static IHtmlString GetBreadCrumbs(this HtmlHelper htmlHelper, FrontEndCmsPage model, string className = "breadcrumb", string label = "", string separator = "/")
        {
            string         breadCrumbs    = string.Empty;
            CmsPages       pages          = new CmsPages();
            PagesLanguages pagesLanguages = new PagesLanguages();

            BuildBreadCrumbs(pages, pagesLanguages, ref breadCrumbs, model.PageId, model.LanguageCode, separator, false);
            if (breadCrumbs.IsNotEmptyOrWhiteSpace())
            {
                if (label.IsNotEmptyOrWhiteSpace())
                {
                    label = "<span>" + label + "</span>";
                }
                breadCrumbs = "<ul class=\"" + className + "\">" + breadCrumbs.Insert(breadCrumbs.IndexOf('>') + 1, label) + "</ul>";
            }
            return(htmlHelper.Raw(breadCrumbs));
        }
Example #8
0
        private static void BuildBreadCrumbs(CmsPages pages, PagesLanguages pageLanguages, ref string breadCrumbs, int?pageId, string langCode, string separator, bool isPreviousHomePage)
        {
            CmsPage page = pages.GetPageByPageId(pageId);

            if (page.IsNotNull())
            {
                PageLanguage pageLanguage = pageLanguages.GetPageLanguage(pageId, langCode);
                string       title        = page.PageName;
                if (pageLanguage.IsNotNull() && pageLanguage.MenuName.IsNotEmptyOrWhiteSpace())
                {
                    title = pageLanguage.MenuName;
                }

                if (breadCrumbs.IsEmptyOrWhiteSpace())
                {
                    breadCrumbs = "<li class=\"active\">" + title + "</li>";
                }
                else
                {
                    GlobalConfiguration globalConfiguration = new GlobalConfigurations().GetGlobalConfiguration();
                    string url = "/";
                    if (!page.IsHomePage || langCode != globalConfiguration.DefaultLanguageCode)
                    {
                        if (page.IsHomePage)
                        {
                            url += langCode + "/";
                        }
                        else
                        {
                            url += langCode + "/" + page.FullSegment + "/";
                        }
                    }
                    breadCrumbs = "<li><a href=\"" + url + "\">" + title + "</a></li>" + breadCrumbs;
                }
                BuildBreadCrumbs(pages, pageLanguages, ref breadCrumbs, page.PageParentId, langCode, separator, page.IsHomePage);
            }
            else if (page.IsNull() && !isPreviousHomePage)
            {
                page = pages.GetHomePage();
                if (page.IsNotNull())
                {
                    BuildBreadCrumbs(pages, pageLanguages, ref breadCrumbs, page.PageId, langCode, separator, page.IsHomePage);
                }
            }
        }
Example #9
0
        private static void BuildMainMenu(List <CmsPage> backEndCmsPageList, int currentLevel, int?pageParentId, ref string mainMenu, string savedNode, string className, string langCode)
        {
            if (backEndCmsPageList != null && currentLevel <= 2)
            {
                List <CmsPage> pagesObj = (from page in backEndCmsPageList
                                           where page.PageParentId == pageParentId &&
                                           page.ShowInMainMenu &&
                                           page.IsActive
                                           select page).ToList();

                if (pagesObj != null && pagesObj.Count() > 0)
                {
                    mainMenu += Environment.NewLine + "<ul";
                    if (currentLevel == 1)
                    {
                        mainMenu += " class=\"" + className + "\"";
                    }
                    else
                    {
                        mainMenu += " class=\"dropdown-menu\"";
                    }
                    mainMenu += ">" + Environment.NewLine;

                    if (savedNode.IsNotEmptyOrWhiteSpace())
                    {
                        mainMenu += savedNode + "<li class=\"divider\"></li>";
                    }

                    GlobalConfiguration globalConfiguration      = new GlobalConfigurations().GetGlobalConfiguration();
                    PagesLanguages      backEndCmsPagesLanguages = new PagesLanguages();
                    PageLanguage        backEndCmsPageLanguage;
                    string pageTitle;
                    foreach (CmsPage pageObj in pagesObj)
                    {
                        backEndCmsPageLanguage = backEndCmsPagesLanguages.GetPageLanguage(pageObj.PageId, langCode);

                        if (backEndCmsPageLanguage.IsNotNull() && backEndCmsPageLanguage.MenuName.IsNotEmptyOrWhiteSpace())
                        {
                            pageTitle = backEndCmsPageLanguage.MenuName;
                        }
                        else
                        {
                            pageTitle = pageObj.PageName;
                        }

                        bool hasChildren = (from page in backEndCmsPageList
                                            where page.PageParentId == pageObj.PageId &&
                                            page.ShowInMainMenu &&
                                            page.IsActive
                                            select page).Count() > 0;

                        mainMenu += "<li";
                        if (hasChildren && currentLevel < 2)
                        {
                            savedNode = "<li><a href=\"/";
                            if (!pageObj.IsHomePage || langCode != globalConfiguration.DefaultLanguageCode)
                            {
                                if (pageObj.IsHomePage)
                                {
                                    savedNode += langCode + "/";
                                }
                                else
                                {
                                    savedNode += langCode + "/" + pageObj.FullSegment + "/";
                                }
                            }
                            savedNode += "\" title=\"" + pageTitle + "\" target=\"" + pageObj.Target + "\">" + pageTitle + "</a></li>";

                            mainMenu += " class=\"dropdown\"";
                        }
                        mainMenu += ">";

                        if (hasChildren && currentLevel < 2)
                        {
                            mainMenu += "<a href=\"#\" title=\"" + pageTitle + "\" target=\"" + pageObj.Target + "\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">" + pageTitle + " <b class=\"caret\"></b></a>";
                        }
                        else
                        {
                            mainMenu += "<a href=\"{$url}\" title=\"" + pageTitle + "\" target=\"" + pageObj.Target + "\">" + pageTitle + "</a>";
                        }

                        if (pageObj.PageTemplateId.IsNull())
                        {
                            mainMenu = mainMenu.Replace("{$url}", pageObj.Url);
                        }
                        else
                        {
                            if (!pageObj.IsHomePage || langCode != globalConfiguration.DefaultLanguageCode)
                            {
                                if (pageObj.IsHomePage)
                                {
                                    mainMenu = mainMenu.Replace("{$url}", "/" + langCode + "/");
                                }
                                else
                                {
                                    mainMenu = mainMenu.Replace("{$url}", "/" + langCode + "/" + pageObj.FullSegment + "/");
                                }
                            }
                            else
                            {
                                mainMenu = mainMenu.Replace("{$url}", "/");
                            }
                        }

                        currentLevel++;

                        BuildMainMenu(backEndCmsPageList, currentLevel, pageObj.PageId, ref mainMenu, savedNode, className, langCode);

                        currentLevel--;

                        mainMenu += "</li>" + Environment.NewLine;
                    }
                    mainMenu += "</ul>" + Environment.NewLine;
                }
            }
        }
Example #10
0
        private static void BuildSitemap(List <CmsPage> backEndCmsPageList, PagesLanguages pagesLanguages, int currentLevel, int?pageParentId, ref string sitemap, string className, string langCode)
        {
            if (backEndCmsPageList != null)
            {
                List <CmsPage> pagesObj = (from page in backEndCmsPageList
                                           where page.PageParentId == pageParentId &&
                                           page.ShowInSitemap &&
                                           page.IsActive
                                           select page).ToList();

                if (pagesObj != null && pagesObj.Count() > 0)
                {
                    sitemap += Environment.NewLine + "<ul";
                    if (currentLevel == 1 && className.IsNotEmptyOrWhiteSpace())
                    {
                        sitemap += " class=\"" + className + "\"";
                    }
                    sitemap += ">" + Environment.NewLine;

                    GlobalConfiguration globalConfiguration = new GlobalConfigurations().GetGlobalConfiguration();

                    PageLanguage backEndCmsPageLanguage;
                    string       pageTitle;
                    string       url;
                    foreach (CmsPage pageObj in pagesObj)
                    {
                        backEndCmsPageLanguage = pagesLanguages.GetPageLanguage(pageObj.PageId, langCode);

                        pageTitle = pageObj.PageName;
                        if (backEndCmsPageLanguage.IsNotNull() && backEndCmsPageLanguage.MenuName.IsNotEmptyOrWhiteSpace())
                        {
                            pageTitle = backEndCmsPageLanguage.MenuName;
                        }

                        if (pageObj.PageTemplateId.IsNull())
                        {
                            url = pageObj.Url;
                        }
                        else
                        {
                            if (!pageObj.IsHomePage || langCode != globalConfiguration.DefaultLanguageCode)
                            {
                                if (pageObj.IsHomePage)
                                {
                                    url = "/" + langCode + "/";
                                }
                                else
                                {
                                    url = "/" + langCode + "/" + pageObj.FullSegment + "/";
                                }
                            }
                            else
                            {
                                url = "/";
                            }
                        }

                        sitemap += "<li><a href=\"" + url + "\" title=\"" + pageTitle + "\" target=\"" + pageObj.Target + "\">" + pageTitle + "</a>";

                        currentLevel++;

                        BuildSitemap(backEndCmsPageList, pagesLanguages, currentLevel, pageObj.PageId, ref sitemap, className, langCode);

                        currentLevel--;

                        sitemap += "</li>" + Environment.NewLine;
                    }
                    sitemap += "</ul>" + Environment.NewLine;
                }
            }
        }
        public static IHtmlString GetPageContent(this HtmlHelper htmlHelper, FrontEndCmsPage model)
        {
            string result = string.Empty;

            PageLanguage backEndCmsPageLanguage = new PagesLanguages().GetPageLanguage(model.PageId, model.LanguageCode);

            string controllerAction;

            string[] controllerActionArray;

            if (model.PageTemplateId.IsNotNull())
            {
                PageTemplate pageTemplate = new PageTemplates().GetPageTemplateById(model.PageTemplateId);

                IEnumerable <IModuleConnector> moduleConnectors = ModuleConnectorsHelper.GetModuleConnectors();

                bool isModuleFound;

                foreach (string templatePart in ExtensionsHelper.GetHtmlCodeParts(pageTemplate.HtmlCode))
                {
                    isModuleFound = false;
                    foreach (IModuleConnector moduleConnector in moduleConnectors)
                    {
                        foreach (SelectListItem module in moduleConnector.GetSelectItemList())
                        {
                            if (templatePart.ToLower() == module.Value.ToLower())
                            {
                                isModuleFound         = true;
                                controllerAction      = templatePart.Substring(2, templatePart.Length - 3);
                                controllerActionArray = controllerAction.Split('-');
                                result += moduleConnector.GetContent(htmlHelper, model, controllerActionArray[1]);
                            }
                        }
                    }

                    if (!isModuleFound)
                    {
                        if (templatePart == "{$Content}")
                        {
                            if (backEndCmsPageLanguage.IsNotNull())
                            {
                                //include any extra modules
                                foreach (string pageLanguagePart in ExtensionsHelper.GetHtmlCodeParts(backEndCmsPageLanguage.HtmlCode))
                                {
                                    isModuleFound = false;
                                    foreach (IModuleConnector moduleConnector in moduleConnectors)
                                    {
                                        foreach (SelectListItem module in moduleConnector.GetSelectItemList())
                                        {
                                            if (pageLanguagePart.ToLower() == module.Value.ToLower())
                                            {
                                                isModuleFound         = true;
                                                controllerAction      = pageLanguagePart.Substring(2, pageLanguagePart.Length - 3);
                                                controllerActionArray = controllerAction.Split('-');
                                                result += moduleConnector.GetContent(htmlHelper, model, controllerActionArray[1]);
                                            }
                                        }
                                    }

                                    if (!isModuleFound)
                                    {
                                        if (pageLanguagePart.StartsWith("{$") && pageLanguagePart.EndsWith("}") && pageLanguagePart.Contains('-'))
                                        {
                                            controllerAction      = pageLanguagePart.Substring(2, pageLanguagePart.Length - 3);
                                            controllerActionArray = controllerAction.Split('-');
                                            try
                                            {
                                                result += htmlHelper.Action(controllerActionArray[1], "FrontEnd" + controllerActionArray[0], model).ToString();
                                            }
                                            catch (Exception ex)
                                            {
                                                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                                            }
                                        }
                                        else
                                        {
                                            result += pageLanguagePart;
                                        }
                                    }
                                }
                            }
                        }
                        else if (templatePart.StartsWith("{$") && templatePart.EndsWith("}") && templatePart.Contains('-'))
                        {
                            controllerAction      = templatePart.Substring(2, templatePart.Length - 3);
                            controllerActionArray = controllerAction.Split('-');
                            result += htmlHelper.Action(controllerActionArray[1], "FrontEnd" + controllerActionArray[0], model).ToString();
                        }
                        else
                        {
                            result += templatePart;
                        }
                    }
                }
            }

            return(htmlHelper.Raw(result.ReplaceGlobalTokens()));
        }
Example #12
0
        public ActionResult Index(string languageCode, string segments)
        {
            GlobalConfiguration globalConfiguration = new GlobalConfigurations().GetGlobalConfiguration();

            if (!globalConfiguration.IsOffline || Request["OfflineCode"] == globalConfiguration.OfflineCode || Session["OfflineCode"].ConvertTo <string>(null, true) == globalConfiguration.OfflineCode)
            {
                if (Session["OfflineCode"].IsNull())
                {
                    Session["OfflineCode"] = Request["OfflineCode"];
                }

                FrontEndCmsPage page = new FrontEndCmsPage()
                {
                    PageId             = null,
                    LanguageCode       = globalConfiguration.DefaultLanguageCode,
                    LanguageFolder     = "",
                    Parameter          = string.Empty,
                    MetaTagTitle       = globalConfiguration.MetaTitle,
                    MetaTagKeywords    = globalConfiguration.MetaKeywords,
                    MetaTagDescription = globalConfiguration.MetaDescription,
                    Robots             = globalConfiguration.Robots,
                    PageTemplateId     = null,
                    StatusCode         = null
                };

                CmsPages cmsPages          = new CmsPages();
                CmsPage  cmsPage           = cmsPages.GetHomePage();
                bool     isHomePageDefined = cmsPage.IsNotNull();

                if (segments.IsNotEmptyOrWhiteSpace())
                {
                    segments = segments.TrimEnd('/');

                    cmsPage = cmsPages.GetPageBySegments(segments);
                    if (cmsPage.IsNull() && segments.Contains('/'))
                    {
                        cmsPage        = cmsPages.GetPageBySegments(segments.Remove(segments.LastIndexOf('/')));
                        page.Parameter = segments.Substring(segments.LastIndexOf('/') + 1); //the parameter can be a dash separated list of parameters. E.g. 2-today_the_weather_is_nice
                    }
                }

                Language language = new Languages().GetLanguageByCode(languageCode);

                if (
                    cmsPage.IsNotNull() &&                                                                             //The page exists
                    (cmsPage.IsActive || (Request["preview"] == "true" && BackEndSessions.CurrentUser.IsNotNull())) && //The page is active or the page is in preview mode with a user logged in the admin area
                    language.IsNotNull() &&                                                                            //The language exists
                    language.IsActive                                                                                  //The language is active
                    )
                {
                    if (cmsPage.IsAccessRestricted && FrontEndSessions.CurrentSubscription.IsNull())
                    {
                        SubscriptionConfiguration subscriptionConfiguration = new SubscriptionConfigurations().GetSubscriptionConfiguration();
                        CmsPageActionlink         cmsPageActionlink         = cmsPages.GetCmsPageActionlink(subscriptionConfiguration.SignInPageId, language.LanguageCode);
                        if (cmsPageActionlink.IsNotNull())
                        {
                            return(Redirect(cmsPageActionlink.Url + "?ReturnUrl=" + HttpUtility.UrlEncode(Request.Url.AbsoluteUri)));
                        }
                    }

                    page.PageId         = cmsPage.PageId;
                    page.LanguageCode   = language.LanguageCode;
                    page.LanguageFolder = language.LanguageCode == globalConfiguration.DefaultLanguageCode ? "" : language.LanguageCode;
                    page.PageTemplateId = cmsPage.PageTemplateId;

                    PageLanguage pageLanguage = new PagesLanguages().GetPageLanguage(cmsPage.PageId, language.LanguageCode);
                    if (pageLanguage.IsNotNull())
                    {
                        if (pageLanguage.MetaTagTitle.IsNotEmptyOrWhiteSpace())
                        {
                            page.MetaTagTitle = pageLanguage.MetaTagTitle.ReplaceGlobalTokens();
                        }

                        if (pageLanguage.MetaTagKeywords.IsNotEmptyOrWhiteSpace())
                        {
                            page.MetaTagKeywords = pageLanguage.MetaTagKeywords.ReplaceGlobalTokens();
                        }

                        if (pageLanguage.MetaTagDescription.IsNotEmptyOrWhiteSpace())
                        {
                            page.MetaTagDescription = pageLanguage.MetaTagDescription.ReplaceGlobalTokens();
                        }

                        if (pageLanguage.Robots.IsNotEmptyOrWhiteSpace())
                        {
                            page.Robots = pageLanguage.Robots;
                        }
                    }
                }
                else
                {
                    if (language.IsNotNull())
                    {
                        page.LanguageCode   = language.LanguageCode;
                        page.LanguageFolder = language.LanguageCode == globalConfiguration.DefaultLanguageCode ? "" : language.LanguageCode;
                    }

                    page.PageTemplateId = globalConfiguration.DefaultErrorPageTemplateId;
                    if (isHomePageDefined)
                    {
                        page.StatusCode = 404;
                    }
                    else
                    {
                        page.StatusCode = 501; //Home page not defined in the database table tb_cms_pages
                    }
                }

                Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture((language.IsNotNull() && language.IsActive) ? language.LanguageCode : page.LanguageCode);

                return(View(page));
            }
            else
            {
                return(Redirect("~/_app_offline.htm"));
            }
        }