Exemple #1
0
        /// <summary>
        /// 添加文章回复
        /// </summary>
        /// <param name="nickName"></param>
        /// <param name="emailAddress"></param>
        /// <param name="blogId"></param>
        /// <param name="content"></param>
        /// <param name="replyId"></param>
        public void AddComment(String nickName, String emailAddress, Guid blogId, String content, Guid replyId = default(Guid))
        {
            if (String.IsNullOrEmpty(nickName))
            {
                throw new ArgumentNullException($"{nickName}");
            }

            if (String.IsNullOrEmpty(emailAddress))
            {
                throw new ArgumentNullException($"{emailAddress}");
            }

            if (String.IsNullOrEmpty(content))
            {
                throw new ArgumentNullException($"{content}");
            }

            if (blogId == Guid.Empty)
            {
                throw new ArgumentNullException($"{blogId}");
            }

            var comment = new Comment(nickName, emailAddress, blogId, content, replyId);

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

            _redisRepository.ListRightPush(commentBlogRedisKey, comment);

            var blogRedisKey = $"NewBlogger:Blogs:Id:{blogId}";

            _redisRepository.HashIncrement(blogRedisKey, "CommentCount");
        }
Exemple #2
0
        /// <summary>
        /// 新增文章标签
        /// </summary>
        /// <param name="tagName"></param>
        public void AddTag(String tagName)
        {
            if (String.IsNullOrEmpty(tagName))
            {
                throw new ArgumentNullException($"{tagName}");
            }

            var tagRedisKey = "NewBlogger:Tags";

            _redisRepository.ListRightPush(tagRedisKey, new Tag(tagName));
        }
Exemple #3
0
        /// <summary>
        /// 新增文章
        /// </summary>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <param name="categoryId"></param>
        /// <param name="tagIds"></param>
        public void AddNewBlog(String title, String content, Guid categoryId, params Guid[] tagIds)
        {
            if (String.IsNullOrEmpty(title))
            {
                throw new ArgumentNullException($"{nameof(title)}");
            }

            if (String.IsNullOrEmpty(content))
            {
                throw new ArgumentNullException($"{nameof(content)}");
            }

            if (categoryId == Guid.Empty)
            {
                throw new ArgumentNullException($"{nameof(categoryId)}");
            }

            if (!tagIds.Any())
            {
                throw new ArgumentNullException($"{nameof(tagIds)}");
            }

            var blog = new Blog(title, content, categoryId, tagIds);

            var blogRedisKey = $"NewBlogger:Blogs:Id:{blog.Id}";

            _redisRepository.HashSet(blogRedisKey, new List <HashEntry>
            {
                new HashEntry(nameof(blog.Id), $"{blog.Id}"),
                new HashEntry(nameof(blog.Title), blog.Title),
                new HashEntry(nameof(blog.Content), blog.Content),
                new HashEntry(nameof(blog.CategoryId), $"{blog.CategoryId}"),
                new HashEntry(nameof(blog.AddTime), $"{blog.AddTime}"),
                new HashEntry(nameof(blog.Tags), JsonConvert.SerializeObject(blog.Tags)),
                new HashEntry(nameof(blog.ViewCount), 0),
                new HashEntry(nameof(blog.CommentCount), 0)
            }.ToArray());

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

            _redisRepository.ListRightPush(blogIdsRedisKey, blog.Id);

            var categoryBlogCountRedisKey = $"NewBlogger:CategoryBlogCount:Category:{categoryId}";

            if (!_redisRepository.KeyExists(categoryBlogCountRedisKey))
            {
                _redisRepository.StringSet(categoryBlogCountRedisKey, 1);
            }
            else
            {
                _redisRepository.StringIncrement(categoryBlogCountRedisKey);
            }
        }
Exemple #4
0
        /// <summary>
        /// 添加文章分类
        /// </summary>
        /// <param name="categoryName"></param>
        public void AddCategory(String categoryName)
        {
            if (String.IsNullOrEmpty(categoryName))
            {
                throw new ArgumentNullException($"{nameof(categoryName)}");
            }

            var category = new Category(categoryName);

            var categoryRedisKey = "NewBlogger:Categorys";

            _redisRepository.ListRightPush(categoryRedisKey, category);
        }