Esempio n. 1
0
        public Task <string> GetRawContentAsync(PostSlugInfo slugInfo)
        {
            var date = new DateTime(slugInfo.Year, slugInfo.Month, slugInfo.Day);
            var spec = new PostSpec(date, slugInfo.Slug);

            return(_postRepo.SelectFirstOrDefaultAsync(spec,
                                                       post => post.PostContent));
        }
Esempio n. 2
0
        public async Task <PostSlug> GetAsync(PostSlugInfo slugInfo)
        {
            var date = new DateTime(slugInfo.Year, slugInfo.Month, slugInfo.Day);
            var spec = new PostSpec(date, slugInfo.Slug);

            var pid = await _postRepository.SelectFirstOrDefaultAsync(spec, p => p.Id);

            if (pid == Guid.Empty)
            {
                return(null);
            }

            var psm = await _cache.GetOrCreateAsync(CacheDivision.Post, $"{pid}", async entry =>
            {
                entry.SlidingExpiration = TimeSpan.FromMinutes(AppSettings.CacheSlidingExpirationMinutes["Post"]);

                var postSlugModel = await _postRepository.SelectFirstOrDefaultAsync(spec, post => new PostSlug
                {
                    Title           = post.Title,
                    ContentAbstract = post.ContentAbstract,
                    PubDateUtc      = post.PubDateUtc.GetValueOrDefault(),

                    Categories = post.PostCategory.Select(pc => pc.Category).Select(p => new Category
                    {
                        DisplayName = p.DisplayName,
                        RouteName   = p.RouteName
                    }).ToArray(),

                    RawPostContent = post.PostContent,
                    Hits           = post.PostExtension.Hits,
                    Likes          = post.PostExtension.Likes,

                    Tags = post.PostTag.Select(pt => pt.Tag)
                           .Select(p => new Tag
                    {
                        NormalizedName = p.NormalizedName,
                        DisplayName    = p.DisplayName
                    }).ToArray(),
                    Id                  = post.Id,
                    CommentEnabled      = post.CommentEnabled,
                    ExposedToSiteMap    = post.ExposedToSiteMap,
                    LastModifyOnUtc     = post.LastModifiedUtc,
                    ContentLanguageCode = post.ContentLanguageCode,
                    CommentCount        = post.Comment.Count(c => c.IsApproved)
                });

                if (null != postSlugModel)
                {
                    postSlugModel.RawPostContent = AddLazyLoadToImgTag(postSlugModel.RawPostContent);
                }

                return(postSlugModel);
            });

            return(psm);
        }
Esempio n. 3
0
        public Task <PostSlugSegment> GetSegmentAsync(PostSlugInfo slugInfo)
        {
            var date = new DateTime(slugInfo.Year, slugInfo.Month, slugInfo.Day);
            var spec = new PostSpec(date, slugInfo.Slug);

            var model = _postRepo.SelectFirstOrDefaultAsync(spec, post => new PostSlugSegment
            {
                Title           = post.Title,
                PubDateUtc      = post.PubDateUtc.GetValueOrDefault(),
                LastModifyOnUtc = post.LastModifiedUtc,

                Categories = post.PostCategory
                             .Select(pc => pc.Category.DisplayName)
                             .ToArray(),

                Tags = post.PostTag
                       .Select(pt => pt.Tag.DisplayName)
                       .ToArray()
            });

            return(model);
        }