Exemplo n.º 1
0
        public bool Update(SitePageSection model)
        {
            try
            {
                if (model.IsHomePageSection)
                {
                    foreach (var page in this.Context.SitePageSection.ToList())
                    {
                        page.IsHomePageSection = false;

                        if (page.SitePageSectionId == model.SitePageSectionId)
                        {
                            page.IsHomePageSection = true;
                        }
                    }
                }

                this.Context.SitePageSection.Update(model);
                this.Context.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex);

                throw new Exception("DB error", ex.InnerException);
            }
        }
Exemplo n.º 2
0
        private StructureDataReviewModel BuildReviewModel(SitePageSection sitePageSection, SitePage sitePage)
        {
            if (sitePage.PageType != PageType.Review)
            {
                return(null);
            }

            var ratingPercentage = (sitePage.ReviewRatingValue / (sitePage.ReviewBestValue - sitePage.ReviewWorstValue)) * 100;

            return(new StructureDataReviewModel(this.cacheService)
            {
                ItemReviewed = new ItemReviewed()
                {
                    Name = sitePage.ReviewItemName
                },
                ReviewRating = new ReviewRating()
                {
                    BestRating = sitePage.ReviewBestValue.ToString("0.0"),
                    RatingValue = sitePage.ReviewRatingValue.ToString("0.0"),
                    WorstRating = sitePage.ReviewWorstValue.ToString("0.0"),
                    RatingPercentage = ratingPercentage.ToString("0.0")
                },

                // Author = new Author()
                // {
                //    Name = StringConstants.WebsiteAuthor //TODO: GET FROM SITEPAGE USER
                // },
                Publisher = new Publisher()
                {
                    Name = this.cacheService.GetSnippet(SiteConfigSetting.WebsiteName)
                }
            });
        }
Exemplo n.º 3
0
        public SitePageSection Create(SitePageSection model)
        {
            try
            {
                this.Context.SitePageSection.Add(model);
                this.Context.SaveChanges();

                return(model);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex);

                throw new Exception("DB error", ex.InnerException);
            }
        }
Exemplo n.º 4
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('/'));
        }
Exemplo n.º 5
0
        private SitePageDisplayModel CreateDisplayModel(SitePageSection sitePageSection, SitePage sitePage)
        {
            var contentModel = this.CreatePageContentModel(sitePageSection, sitePage);
            var comments     = this.BuildComments(sitePage);

            var displayModel = new SitePageDisplayModel(this.cacheService)
            {
                BreadcrumbList  = this.BuildBreadcrumbList(sitePageSection, sitePage),
                PageType        = sitePage.PageType,
                Review          = this.BuildReviewModel(sitePageSection, sitePage),
                PageContent     = contentModel,
                Comments        = comments,
                AllowCommenting = sitePage.AllowsComments,
            };

            displayModel.PostComment.SitePageId = sitePage.SitePageId;

            return(displayModel);
        }
Exemplo 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);
        }
Exemplo n.º 7
0
        public static string GetpPageCacheKey(SitePageSection sitePageSection)
        {
            var cacheKey = $"sitepagesection-{sitePageSection.Key}".ToLower();

            return(cacheKey);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        private SitePageDisplayModel CreateDisplayListModel(
            SitePageSection sitePageSection = null,
            SitePage sitePage = null,
            string tagKey     = null,
            int pageNumber    = 1)
        {
            var             displayModel = new SitePageDisplayModel(this.cacheService);
            List <SitePage> pages;
            int             total = 0;

            if (string.IsNullOrWhiteSpace(tagKey))
            {
                var contentModel = this.CreatePageContentModel(sitePageSection, sitePage);

                displayModel = new SitePageDisplayModel(this.cacheService)
                {
                    BreadcrumbList = this.BuildBreadcrumbList(sitePageSection, sitePage),
                    PageType       = sitePage.PageType,
                    Review         = this.BuildReviewModel(sitePageSection, sitePage),
                    PageContent    = contentModel
                };

                pages = this.sitePageRepository.GetLivePageBySection(
                    sitePageSection.SitePageSectionId,
                    pageNumber,
                    PageSize,
                    out total);

                pages = pages.Where(x => x.IsSectionHomePage == false).ToList();
            }
            else
            {
                displayModel.TagKey                      = tagKey;
                displayModel.TagKeyword                  = this.tagRepository.Get(tagKey).Name;
                displayModel.PageContent.Title           = $"{displayModel.TagKeyword} - Pages Tagged";
                displayModel.PageContent.PageHeader      = displayModel.PageContent.Title;
                displayModel.PageContent.MetaDescription = $"Pages which are tagged {displayModel.TagKeyword}";
                displayModel.PageType                    = PageType.PageList;

                pages = this.sitePageRepository.GetLivePageByTag(
                    tagKey,
                    pageNumber,
                    PageSize,
                    out total);
            }

            var pageCount = (double)total / PageSize;

            displayModel.Paging = new SitePagePagingModel()
            {
                CurrentPageNumber = pageNumber,
                PageCount         = (int)Math.Ceiling(pageCount),
                QuantityPerPage   = PageSize,
                Total             = total
            };

            foreach (var page in pages)
            {
                var itemPageModel = this.CreatePageContentModel(page.SitePageSection, page);

                if (itemPageModel.IsIndex)
                {
                    continue;
                }

                displayModel.Items.Add(itemPageModel);
            }

            return(displayModel);
        }