Пример #1
0
        public static Website GetWebsite(long versionNumber = 0, Language language = null)
        {
            if (language == null)
            {
                language = FrameworkSettings.GetCurrentLanguage();
            }

            var key = "GetWebsite?version=" + versionNumber + "&languageId=" + language.ID;

            var website = ContextHelper.GetFromRequestContext(key);

            if (website != null)
            {
                return((Website)website);
            }

            website = WebsitesMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.HistoryVersionNumber == versionNumber && i.MediaType.Name == enumName && i.LanguageID == language.ID);

            if (website == null)
            {
                var defaultLanguage = LanguagesMapper.GetDefaultLanguage();
                website = WebsitesMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.HistoryVersionNumber == versionNumber && i.MediaType.Name == enumName && i.LanguageID == defaultLanguage.ID);
            }

            ContextHelper.SetToRequestContext(key, website);

            return((Website)website);
        }
        public static UrlRedirectRule CreateUrlRedirect(string fromVirtualPath, Media toMedia)
        {
            var currentLanuageId = FrameworkSettings.GetCurrentLanguage().ID;
            var urlRedirectList  = MediaDetailsMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.MediaType.Name == MediaTypeEnum.UrlRedirectRuleList.ToString() && i.HistoryVersionNumber == 0 && i.LanguageID == currentLanuageId);
            var mediaType        = MediaDetailsMapper.GetDataModel().MediaTypes.FirstOrDefault(i => i.Name == MediaTypeEnum.UrlRedirectRule.ToString());

            if (urlRedirectList != null && mediaType != null)
            {
                fromVirtualPath = fromVirtualPath.Replace("~", "");

                var urlRewrite = (UrlRedirectRule)MediaDetailsMapper.CreateObject(mediaType.ID, null, urlRedirectList.Media);
                urlRewrite.Is301Redirect         = true;
                urlRewrite.VirtualPathToRedirect = fromVirtualPath;
                urlRewrite.RedirectToUrl         = toMedia.PermaShortCodeLink;
                urlRewrite.LinkTitle             = urlRewrite.SectionTitle = urlRewrite.Title = urlRewrite.VirtualPathToRedirect + " -> " + urlRewrite.RedirectToUrl;
                urlRewrite.PublishDate           = DateTime.Now;

                var user = UsersMapper.GetAllByRoleEnum(RoleEnum.Administrator).FirstOrDefault(i => i.IsActive);

                if (user != null)
                {
                    urlRewrite.CreatedByUser = urlRewrite.LastUpdatedByUser = user;
                }

                return(urlRewrite);
            }

            return(null);
        }
Пример #3
0
        public IMediaDetail GetLiveMediaDetail(Language language = null)
        {
            if (language == null)
            {
                var currentLanguage = FrameworkSettings.GetCurrentLanguage();
                language = currentLanguage;
            }

            return(this.MediaDetails.SingleOrDefault(i => i.HistoryForMediaDetail == null && i.LanguageID == language.ID && ((i.MediaType != null)? i.MediaType.ShowInSiteTree : false)));
        }