Esempio n. 1
0
        public IEnumerable <GroupWallResponseModel> GetGroupWall(string groupId, int skip, int size)
        {
            //TODO:Optimize with sp
            List <GroupWallResponseModel> response = new List <GroupWallResponseModel>();

            using (var entities = new SocialFeedEntities())
            {
                var posts = entities.GroupWall.Include("WallPost")
                            .Where(p => p.GroupId == groupId && p.WallPost.IsDeleted == false)
                            .OrderByDescending(p => p.WallPost.CreatedDate).Skip(skip).Take(size).ToList();

                //TODO:Optimize with sp
                foreach (var post in posts)
                {
                    var postLikes    = entities.WallPostLike.Count(p => p.WallPostId == post.WallPostId);
                    var postComments = entities.UserComment.Count(p => p.WallPostId == post.WallPostId);

                    var item = new GroupWallResponseModel
                    {
                        Body         = post.WallPost.Body,
                        CommentCount = postComments,
                        CreatedDate  = post.WallPost.CreatedDate,
                        Id           = post.WallPostId,
                        LikeCount    = postLikes,
                        ModifiedDate = post.WallPost.ModifiedDate,
                        PostedBy     = post.WallPost.CreatedBy,
                        PostType     = post.WallPost.PostType,
                        WallOwner    = new WallModel {
                            OwnerId = post.GroupId, WallOwnerType = WallType.group
                        }
                    };

                    response.Add(item);
                }
            }
            return(response);
        }
Esempio n. 2
0
        public IEnumerable <GroupWallResponseModel> GetGroupWall(string groupId)
        {
            var result     = new List <GroupWallResponseModel>();
            var key        = GetEntryKey(FeedPrefix, groupId);
            var db         = StackExchangeRedisConnectionProvider.GetDataBase();
            var allPostIds = db.SetMembers(key).ToList();

            if (allPostIds != null && allPostIds.Count > 0)
            {
                var postKeys = allPostIds.Select(p => (RedisKey)GetEntryKey(RedisNameConstants.WallPostRepoPrefix, p)).ToArray();
                var likeKeys = allPostIds.Select(p => (RedisKey)GetEntryKey(RedisNameConstants.PostLikeCounterNamePrefix, p)).ToArray();
                var comment  = allPostIds.Select(p => (RedisKey)GetEntryKey(RedisNameConstants.CommentCounterNamePrefix, p)).ToArray();
                //foreach (var postId in allPostIds)
                //{

                //var transaction = db.CreateTransaction();
                //var posts = transaction.StringGetAsync(postKeys);
                var posts = db.StringGet(postKeys);
                foreach (var post in posts)
                {
                    var currentPost = JsonConvert.DeserializeObject <WallPostCacheModel>(post);

                    var model = new GroupWallResponseModel
                    {
                        Body         = currentPost.Body,
                        CreatedDate  = currentPost.CreatedDate,
                        Id           = currentPost.Id,
                        ModifiedDate = currentPost.ModifiedDate,
                        PostedBy     = currentPost.PostedBy,
                        PostType     = currentPost.PostType,
                        WallOwner    = new WallModel {
                            OwnerId = currentPost.TargetWall.Id, WallOwnerType = (WallType)currentPost.TargetWall.WallOwnerTypeId
                        },
                    };

                    var currentCommentCountEntry = GetEntryKey(RedisNameConstants.CommentCounterNamePrefix, currentPost.Id);
                    var totalCommentCountEntry   = db.StringGet(currentCommentCountEntry);
                    model.CommentCount = !string.IsNullOrWhiteSpace(totalCommentCountEntry) ? Convert.ToInt32(totalCommentCountEntry) : 0;

                    var totalLikeCountEntryKey = GetEntryKey(RedisNameConstants.PostLikeCounterNamePrefix, currentPost.Id);
                    var value = db.StringGet(totalLikeCountEntryKey);
                    model.LikeCount = !string.IsNullOrWhiteSpace(value) ? Convert.ToInt32(value) : 0;
                    result.Add(model);
                }
                //JsonConvert.DeserializeObject<List<WallPostCacheModel>>();


                //    var comments = transaction.StringGetAsync(comment);
                //    transaction.Execute();


                // var entryKey = GetEntryKey(RedisNameConstants.WallPostRepoPrefix, postId);
                // var currentPostValue = db.StringGet(entryKey);
                //// var currentPost =  !string.IsNullOrWhiteSpace(currentPostValue) ? JsonConvert.DeserializeObject<WallPostCacheModel>(currentPostValue) : null;
                // if (!string.IsNullOrWhiteSpace(currentPostValue))
                // {
                //     //var currentCommentCountEntry = GetEntryKey(RedisNameConstants.CommentCounterNamePrefix, postId);
                //     //var totalCommentCountEntry = db.StringGet(currentCommentCountEntry);
                //     //var totalCommentCount = !string.IsNullOrWhiteSpace(totalCommentCountEntry) ? Convert.ToInt32(totalCommentCountEntry) : 0;

                //     //var totalLikeCountEntryKey = GetEntryKey(RedisNameConstants.PostLikeCounterNamePrefix, postId);
                //     //var value = db.StringGet(entryKey);
                //     //var totalLikeCount =  !string.IsNullOrWhiteSpace(value) ? Convert.ToInt32(value) : 0;

                //     var model = new GroupWallResponseModel
                //     {
                //         //Body = currentPost.Body,
                //         //CreatedDate = currentPost.CreatedDate,
                //         Id = "123"//,
                //         //ModifiedDate = currentPost.ModifiedDate,
                //         //PostedBy = currentPost.PostedBy,
                //         //PostType = currentPost.PostType,
                //         //WallOwner = new WallModel { OwnerId = currentPost.TargetWall.Id, WallOwnerType = (WallType)currentPost.TargetWall.WallOwnerTypeId },
                //         //LikeCount = totalLikeCount,
                //         //CommentCount = totalCommentCount
                //     };
                //     result.Add(model);
                //}
                //}
            }
            return(result);
        }