示例#1
0
        public long AddComment(CommentCreateRequest request)
        {
            var result = commentRepo.SaveComment(request);

            if (result != null && result.Id > 0)
            {
                var cacheModel = new CommentCacheModel
                {
                    Body        = request.Body,
                    CommentId   = result.Id,
                    CreatedBy   = request.CreatedBy,
                    CreatedDate = result.CreatedDate,
                    PostId      = request.WallPostId
                };
                try
                {
                    commentCounterCacheRepo.Increment(cacheModel.PostId);
                }
                catch (Exception ex)
                {
                    logger.Error(string.Format(
                                     "[AddComment] Error incrementing comment count for postId : {0}", cacheModel.PostId), ex);
                }

                return(result.Id);
            }
            return(0);
        }
        public void AddComment(CommentCacheModel model)
        {
            var commentId        = model.CommentId.ToString();
            var entryKey         = GetEntryKey(RepoPrefix, commentId);
            var postCommentCount = GetEntryKey(RedisNameConstants.CommentCounterNamePrefix, model.PostId);

            //var latestCommentsListKey = GetEntryKey(ListRepoPrefix, model.PostId);

            using (var redisClient = GetClientInstance())
            {
                //Save comment
                var clientApi = GetTypedClientApi <CommentCacheModel>(redisClient);
                clientApi.SetValue(entryKey, model);

                //Increment post comment count
                redisClient.Increment(postCommentCount, 1);
            }
        }