Exemple #1
0
        /// <summary>
        /// 获取文章标签列表
        /// </summary>
        /// <returns></returns>
        public IList <TagDto> GetTags()
        {
            var tagRedisKey = "NewBlogger:Tags";

            return(_redisRepository.ListRange <Tag>(tagRedisKey).Select(s => new TagDto
            {
                AddTime = s.AddTime,
                Id = s.Id,
                Name = s.Name
            }).ToList());
        }
Exemple #2
0
        /// <summary>
        /// 获取文章分类列表
        /// </summary>
        /// <returns></returns>
        public IList <CategoryDto> GetCategorys()
        {
            var categoryRedisKey = "NewBlogger:Categorys";

            var categoryBlogCountRedisKey = "NewBlogger:CategoryBlogCount:Category:";

            return(_redisRepository.ListRange <Category>(categoryRedisKey).Select(s => new CategoryDto
            {
                BlogCount = !String.IsNullOrEmpty(_redisRepository.StringGet(categoryBlogCountRedisKey + s.Id)) ? Int32.Parse(_redisRepository.StringGet(categoryBlogCountRedisKey + s.Id)) : 0,
                Id = s.Id,
                Name = s.Name
            }).ToList());
        }
Exemple #3
0
        /// <summary>
        /// 获取文章列表
        /// </summary>
        /// <param name="categoryId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public IList <BlogDto> GetBlogs(Guid categoryId, Int32 pageIndex, Int32 pageSize, out Int32 totalCount)
        {
            //Int32 internalStart = (pageIndex - 1) * pageSize, internalEnd = (pageSize + internalStart) - 1;

            var blogIdsRedisKey = $"NewBlogger:BlogIds:Id";

            var blogIds = _redisRepository.ListRange <Guid>(blogIdsRedisKey, 0, -1);

            var blogs = blogIds.Select(GetBlog).Where(w => categoryId == Guid.Empty || w.CategoryId == categoryId);

            totalCount = blogs.Count();

            return(blogs.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList());
        }
Exemple #4
0
        /// <summary>
        /// 获取文章回复列表
        /// </summary>
        /// <param name="blogId"></param>
        /// <returns></returns>
        public IList <CommentDto> GetComments(Guid blogId)
        {
            if (blogId == Guid.Empty)
            {
                throw new ArgumentNullException($"{blogId}");
            }

            var commentBlogRedisKey = $"NewBlogger:Comments:BlogId:{blogId}";

            return(_redisRepository.ListRange <Comment>(commentBlogRedisKey, 0, -1).Select(comment => new CommentDto
            {
                Id = comment.Id,
                ReplyNickName = comment.ReplyNickName,
                ReplyEmailAddress = comment.ReplyEmailAddress,
                Content = comment.Content,
                BlogId = comment.BlogId,
                AddTime = comment.AddTime
            }).ToList());
        }