Ejemplo n.º 1
0
        public IActionResult Index()
        {
            int total;
            var allBlogs = _blogEntryRepository.GetLivePage(1, int.MaxValue, out total);

            var siteMapHelper = new SiteMapHelper();

            foreach (var blog in allBlogs)
            {
                if (!blog.IsLive)
                {
                    continue;
                }

                var url = new Uri(HttpContext.Request.Scheme +
                                  "://" +
                                  HttpContext.Request.Host.ToUriComponent() +
                                  UrlBuilder.BlogUrlPath(blog.Key, blog.BlogPublishDateTimeUtc));

                var lastUpdated = blog.UpdateDate == null ? blog.CreateDate : (DateTime)blog.UpdateDate;
                siteMapHelper.AddUrl(url.ToString(), lastUpdated, ChangeFrequency.weekly, .5);
            }

            var xml = siteMapHelper.GenerateXml();

            return(Content(xml, "text/xml"));
        }
Ejemplo n.º 2
0
        public IActionResult Index()
        {
            var allPages = this.sitePageRepository.GetLivePage(1, MaxPageSizeForSiteMap, out int total);

            var siteMapHelper = new SiteMapHelper();

            foreach (var page in allPages)
            {
                if (!page.IsLive || page.ExcludePageFromSiteMapXml)
                {
                    continue;
                }

                string url;
                if (page.IsSectionHomePage)
                {
                    url = new Uri(UrlBuilder.GetCurrentDomain(this.HttpContext)).ToString();
                }
                else
                {
                    url = new Uri(UrlBuilder.GetCurrentDomain(this.HttpContext) +
                                  UrlBuilder.BlogUrlPath(page.SitePageSection.Key, page.Key)).ToString().TrimEnd('/');
                }

                var lastUpdated = page.UpdateDate == null ? page.CreateDate : (DateTime)page.UpdateDate;
                siteMapHelper.AddUrl(url, lastUpdated, ChangeFrequency.Weekly, .5);
            }

            var xml = siteMapHelper.GenerateXml();

            return(this.Content(xml, "text/xml"));
        }
Ejemplo n.º 3
0
        private SitePageEditModel ToUiEditModel(SitePage dbModel, bool isHomePageSection)
        {
            var model = new SitePageEditModel()
            {
                Key                       = dbModel.Key,
                BreadcrumbName            = dbModel.BreadcrumbName,
                Content                   = dbModel.Content,
                PageHeader                = dbModel.PageHeader,
                Title                     = dbModel.Title,
                SitePageId                = dbModel.SitePageId,
                PublishDateTimeUtc        = dbModel.PublishDateTimeUtc,
                IsLive                    = dbModel.IsLive,
                ExcludePageFromSiteMapXml = dbModel.ExcludePageFromSiteMapXml,
                LiveUrlPath               = UrlBuilder.BlogUrlPath(dbModel.SitePageSection.Key, dbModel.Key),
                PreviewUrlPath            = UrlBuilder.BlogPreviewUrlPath(dbModel.SitePageId),
                MetaDescription           = dbModel.MetaDescription,
                PageType                  = dbModel.PageType,
                ReviewBestValue           = dbModel.ReviewBestValue,
                ReviewItemName            = dbModel.ReviewItemName,
                ReviewRatingValue         = dbModel.ReviewRatingValue,
                ReviewWorstValue          = dbModel.ReviewWorstValue,
                MetaKeywords              = dbModel.MetaKeywords,
                AllowsComments            = dbModel.AllowsComments,
                IsSectionHomePage         = dbModel.IsSectionHomePage,
            };

            var mc = new ModelConverter(this.cacheService);

            foreach (var photo in dbModel.Photos.OrderBy(x => x.Rank))
            {
                model.BlogPhotos.Add(new SitePagePhotoModel
                {
                    SitePagePhotoId       = photo.SitePagePhotoId,
                    IsDefault             = photo.IsDefault,
                    PhotoUrl              = photo.PhotoUrl,
                    PhotoCdnUrl           = mc.ConvertBlobToCdnUrl(photo.PhotoUrl),
                    PhotoThumbCdnUrl      = mc.ConvertBlobToCdnUrl(photo.PhotoThumbUrl),
                    PhotoFullScreenCdnUrl = mc.ConvertBlobToCdnUrl(photo.PhotoFullScreenUrl),
                    PhotoPreviewCdnUrl    = mc.ConvertBlobToCdnUrl(photo.PhotoPreviewUrl),
                    Title       = photo.Title,
                    Description = photo.Description
                });
            }

            foreach (var tagItem in dbModel.SitePageTags.OrderBy(x => x.Tag.Name))
            {
                model.BlogTags.Add(tagItem.Tag.Name);
            }

            model.BlogTags = model.BlogTags.OrderBy(x => x).ToList();

            model.Tags = string.Join(", ", model.BlogTags);

            return(model);
        }
Ejemplo n.º 4
0
        public IActionResult SiteMap()
        {
            var model      = new HtmlSiteMapModel();
            var allPages   = this.sitePageRepository.GetLivePage(1, int.MaxValue, out int total);
            var sectionIds = allPages.Select(x => x.SitePageSectionId).Distinct();

            foreach (var sectionId in sectionIds)
            {
                var section           = this.sitePageSectionRepository.Get(sectionId);
                var allPagesInSection = allPages.Where(x => x.SitePageSectionId == sectionId).ToList();
                var indexPage         = allPagesInSection.FirstOrDefault(x => x.IsSectionHomePage == true);

                if (indexPage == null)
                {
                    continue;
                }

                var sectionUrl = this.GetSectionUrl(section, indexPage);

                var siteSectionPage =
                    new SectionPage()
                {
                    AnchorText   = indexPage.BreadcrumbName,
                    CanonicalUrl = sectionUrl
                };

                foreach (var page in allPagesInSection)
                {
                    if (!page.IsLive || page.IsSectionHomePage)
                    {
                        continue;
                    }

                    var pagePath = UrlBuilder.BlogUrlPath(page.SitePageSection.Key, page.Key);
                    var pageUrl  = new Uri(UrlBuilder.GetCurrentDomain(this.HttpContext) + pagePath).ToString().TrimEnd('/');

                    siteSectionPage.ChildPages.Add(
                        new SectionPage()
                    {
                        CanonicalUrl = pageUrl,
                        AnchorText   = page.BreadcrumbName
                    });
                }

                siteSectionPage.ChildPages = siteSectionPage.ChildPages.OrderBy(x => x.AnchorText).ToList();

                model.SectionPages.Add(siteSectionPage);
            }

            model.SectionPages = model.SectionPages.OrderBy(x => x.AnchorText).ToList();

            return(this.View("Index", model));
        }
Ejemplo n.º 5
0
        private string GetSectionUrl(SitePageSection section, SitePage indexPage)
        {
            var sectionPath = UrlBuilder.BlogUrlPath(indexPage.SitePageSection.Key, indexPage.Key);

            if (section.IsHomePageSection && indexPage.IsSectionHomePage)
            {
                return(new Uri(UrlBuilder.GetCurrentDomain(this.HttpContext)).ToString().TrimEnd('/'));
            }

            if (indexPage.IsSectionHomePage)
            {
                return(new Uri(
                           $"{UrlBuilder.GetCurrentDomain(this.HttpContext)}/{indexPage.SitePageSection.Key}").ToString().TrimEnd('/'));
            }

            return(new Uri(
                       $"{UrlBuilder.GetCurrentDomain(this.HttpContext)}{sectionPath}").ToString().TrimEnd('/'));
        }
Ejemplo n.º 6
0
        private SitePageContentModel CreatePageContentModel(SitePageSection sitePageSection, SitePage sitePage)
        {
            var blobPrefix = this.cacheService.GetSnippet(SiteConfigSetting.BlobPrefix);
            var cdnPrefix  = this.cacheService.GetSnippet(SiteConfigSetting.CdnPrefixWithProtocol);

            var canonicalUrl = new Uri(UrlBuilder.GetCurrentDomain(this.HttpContext) +
                                       UrlBuilder.BlogUrlPath(sitePageSection.Key, sitePage.Key));

            var defaultPhotoUrl = sitePage?.Photos.FirstOrDefault(x => x.IsDefault == true);

            var displayModel = new SitePageContentModel()
            {
                BreadcrumbName         = sitePage.BreadcrumbName,
                Title                  = sitePage.Title,
                PageHeader             = sitePage.PageHeader,
                MetaDescription        = sitePage.MetaDescription,
                Content                = sitePage.Content,
                LastUpdatedDateTimeUtc = sitePage.UpdateDate ?? sitePage.CreateDate,
                PublishedDateTime      = sitePage.PublishDateTimeUtc,
                CanonicalUrl           = canonicalUrl.ToString(),
                PhotoUrl               = this.ConvertBlobToCdnUrl(blobPrefix, cdnPrefix, defaultPhotoUrl?.PhotoFullScreenUrl),
                PhotoUrlHeight         = defaultPhotoUrl != null ? defaultPhotoUrl.PhotoFullScreenUrlHeight : 0,
                PhotoUrlWidth          = defaultPhotoUrl != null ? defaultPhotoUrl.PhotoFullScreenUrlWidth : 0,
                MetaKeywords           = sitePage.MetaKeywords,
                UrlPath                = UrlBuilder.BlogUrlPath(sitePageSection.Key, sitePage.Key),
                Key        = sitePage.Key,
                SectionKey = sitePageSection.Key,
                DefaultPhotoThumbCdnUrl = this.ConvertBlobToCdnUrl(blobPrefix, cdnPrefix, defaultPhotoUrl?.PhotoThumbUrl)
            };

            if (displayModel.Tags != null)
            {
                foreach (var tagEntry in sitePage.SitePageTags)
                {
                    displayModel.Tags.Add(tagEntry.Tag.Name);
                }

                displayModel.Tags = displayModel.Tags.OrderBy(x => x).ToList();
            }

            return(displayModel);
        }
Ejemplo n.º 7
0
        private BlogManagementListModel ConvertToListModel(List <BlogEntry> blogEntries)
        {
            var model = new BlogManagementListModel();

            foreach (var entry in blogEntries)
            {
                model.Items.Add(new BlogManagementEntryItemModel()
                {
                    BlogEntryId    = entry.BlogEntryId,
                    CreateDate     = entry.CreateDate,
                    Title          = entry.Title,
                    IsLive         = entry.IsLive,
                    Key            = entry.Key,
                    LiveUrlPath    = UrlBuilder.BlogUrlPath(entry.Key, entry.BlogPublishDateTimeUtc),
                    PreviewUrlPath = UrlBuilder.BlogPreviewUrlPath(entry.Key)
                });
            }

            return(model);
        }
Ejemplo n.º 8
0
        private SitePageListModel ConvertToListModel(List <SitePage> pages)
        {
            var model = new SitePageListModel();

            foreach (var page in pages)
            {
                model.Items.Add(new SitePageItemModel()
                {
                    SitePageId     = page.SitePageId,
                    CreateDate     = page.CreateDate,
                    Title          = page.Title,
                    IsLive         = page.IsLive,
                    Key            = page.Key,
                    LiveUrlPath    = UrlBuilder.BlogUrlPath(page.SitePageSection.Key, page.Key),
                    PreviewUrlPath = UrlBuilder.BlogPreviewUrlPath(page.SitePageId),
                    IsIndex        = page.IsSectionHomePage
                });
            }

            return(model);
        }
Ejemplo n.º 9
0
        private BlogManagementEditModel ToUiEditModel(BlogEntry dbModel)
        {
            var model = new BlogManagementEditModel()
            {
                Content                = dbModel.Content,
                Title                  = dbModel.Title,
                BlogEntryId            = dbModel.BlogEntryId,
                BlogPublishDateTimeUtc = dbModel.BlogPublishDateTimeUtc,
                IsLive                 = dbModel.IsLive,
                LiveUrlPath            = UrlBuilder.BlogUrlPath(dbModel.Key, dbModel.BlogPublishDateTimeUtc),
                PreviewUrlPath         = UrlBuilder.BlogPreviewUrlPath(dbModel.Key),
                MetaDescription        = dbModel.MetaDescription
            };

            foreach (var photo in dbModel.Photos.OrderBy(x => x.Rank))
            {
                model.BlogPhotos.Add(new BlogPhotoModel
                {
                    BlogEntryPhotoId = photo.BlogEntryPhotoId,
                    IsDefault        = photo.IsDefault,
                    PhotoUrl         = photo.PhotoUrl,
                    PhotoThumbUrl    = photo.PhotoThumbUrl,
                    Title            = photo.Title,
                    Description      = photo.Description
                });
            }

            foreach (var tagItem in dbModel.BlogEntryTags.OrderBy(x => x.Tag.Name))
            {
                model.BlogTags.Add(tagItem.Tag.Name);
            }

            model.BlogTags = model.BlogTags.OrderBy(x => x).ToList();

            model.Tags = string.Join(", ", model.BlogTags);

            return(model);
        }
Ejemplo n.º 10
0
        private StructuredDataBreadcrumbModel BuildBreadcrumbList(SitePageSection sitePageSection, SitePage sitePage)
        {
            var domain = UrlBuilder.GetCurrentDomain(this.HttpContext);

            var             cacheKey = CacheHelper.GetpPageCacheKey(sitePageSection);
            SitePageSection homeSection;
            var             cachedValue = this.memoryCache.Get(cacheKey);

            if (cachedValue != null)
            {
                homeSection = (SitePageSection)cachedValue;
            }
            else
            {
                homeSection = this.sitePageSectionRepository.GetHomeSection();

                this.memoryCache.Set(cacheKey, homeSection, DateTime.UtcNow.AddMinutes(10));
            }

            if (homeSection == null)
            {
                return(new StructuredDataBreadcrumbModel());
            }

            var breadcrumbList = new StructuredDataBreadcrumbModel()
            {
                ItemListElement = new List <BreadcrumbListItem>()
                {
                    new BreadcrumbListItem()
                    {
                        Position = 1,
                        Item     = new BreadcrumbListItemProperties()
                        {
                            Name    = homeSection.BreadcrumbName,
                            PageUrl = new Uri(domain)
                        }
                    }
                }
            };

            if (!sitePageSection.IsHomePageSection)
            {
                breadcrumbList.ItemListElement.Add(new BreadcrumbListItem()
                {
                    Position = 2,
                    Item     = new BreadcrumbListItemProperties()
                    {
                        Name    = sitePageSection.BreadcrumbName,
                        PageUrl = new Uri(new Uri(domain), sitePageSection.Key),
                    },
                });
            }

            if (!sitePage.IsSectionHomePage)
            {
                breadcrumbList.ItemListElement.Add(
                    new BreadcrumbListItem()
                {
                    Position = 3,
                    Item     = new BreadcrumbListItemProperties()
                    {
                        Name    = sitePage.BreadcrumbName,
                        PageUrl = new Uri(new Uri(domain), UrlBuilder.BlogUrlPath(sitePageSection.Key, sitePage.Key))
                    }
                });
            }

            return(breadcrumbList);
        }