Beispiel #1
0
        public override GetCircleCommentsResponseBody ExecuteCore()
        {
            GetCircleCommentsResponseBody res = new GetCircleCommentsResponseBody();
            var comments = db.t_circle_comment.Where(c => c.circle_id == this.request.CircleId && c.id > this.request.LastCommentId)
                           .Take(this.request.Count)
                           .Select(c => new
            {
                Id            = c.id,
                CircleId      = c.circle_id,
                CommentUserId = c.com_user_id,
                ReplyUserId   = c.reply_user_id,
                Content       = c.com_content,
                CommentTime   = c.comment_time
            }).OrderBy(c => c.Id).ToList();

            if (comments == null || comments.Count <= 0)
            {
                return(res);
            }
            res.CircleCommentInfos = new List <CircleCommentInfo>();

            var userIds    = comments.Select(c => c.CommentUserId).Union(comments.Select(c => c.ReplyUserId)).ToList();
            var userList   = db.t_user.Where(i => userIds.Contains(i.id)).Select(i => new { i.id, i.name, i.symbol, i.head_image }).ToList();
            var friendList = db.t_user_friend.Where(f => f.user_id == this.request.UserId && userIds.Contains(f.friend_user_id)).Select(f => new { f.friend_user_id, f.friend_user_remark }).ToList();

            comments.ForEach(f =>
            {
                CircleCommentInfo model = new CircleCommentInfo()
                {
                    CommentId        = f.Id,
                    Content          = f.Content,
                    CircleId         = f.CircleId,
                    CommentTime      = f.CommentTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    CommentUserId    = f.CommentUserId,
                    CommentUserImage = null,
                    CommentUserName  = null,
                    ReplyUserId      = f.ReplyUserId,
                    ReplyUserName    = null,
                    ReplyUserImage   = null,
                };

                if (userList != null && userList.Count > 0)
                {
                    if (f.CommentUserId > 0)
                    {
                        var comUser            = userList.Where(u => u.id == f.CommentUserId).FirstOrDefault();
                        string friendRemark    = friendList != null ? friendList.Where(r => r.friend_user_id == f.CommentUserId).Select(r => r.friend_user_remark).FirstOrDefault() : null;
                        model.CommentUserName  = UserUtility.GetShowName(friendRemark, comUser.name);
                        model.CommentUserImage = comUser.head_image;
                    }

                    if (f.ReplyUserId > 0)
                    {
                        var repUser          = userList.Where(u => u.id == f.ReplyUserId).FirstOrDefault();
                        string friendRemark  = friendList != null ? friendList.Where(r => r.friend_user_id == f.ReplyUserId).Select(r => r.friend_user_remark).FirstOrDefault() : null;
                        model.ReplyUserName  = UserUtility.GetShowName(friendRemark, repUser.name);
                        model.ReplyUserImage = repUser.head_image;
                    }
                }
                res.CircleCommentInfos.Add(model);
            });

            return(res);
        }
Beispiel #2
0
        public override AddCommentInfoResponseBody ExecuteCore()
        {
            AddCommentInfoResponseBody res = new AddCommentInfoResponseBody();

            var circleModel = db.t_circle.Where(c => c.id == this.request.CircleId).FirstOrDefault();

            if (circleModel == null)
            {
                throw new Exception("你评论的信息已经被用户删除");
            }

            bool isChanged = string.IsNullOrEmpty(this.request.CircleUpdateTime) || this.request.CircleUpdateTime != GenericUtility.FormatDate2(circleModel.update_time);

            t_circle_comment model = new t_circle_comment()
            {
                com_user_id   = this.request.CommentUserId,
                com_content   = this.request.Content,
                circle_id     = this.request.CircleId,
                reply_user_id = this.request.ReplyUserId,
                id            = 0,
                comment_time  = DateTime.Now,
            };

            db.t_circle_comment.Add(model);
            circleModel.comment_count = circleModel.comment_count + 1;
            circleModel.update_time   = DateTime.Now;
            db.SaveChanges();

            var userList           = db.t_user.Where(i => i.id == model.com_user_id || i.id == model.reply_user_id).Select(i => new { i.id, i.name, i.symbol, i.head_image }).ToList();
            CircleCommentInfo info = new CircleCommentInfo()
            {
                CommentId     = model.id,
                Content       = model.com_content,
                CommentTime   = model.comment_time.ToString("yyyy-MM-dd HH:mm:ss"),
                CommentUserId = model.com_user_id,
                //CommentUserImage = model.com,
                //CommentUserName = model.content_info,
                CircleId    = model.circle_id,
                ReplyUserId = model.reply_user_id,
                //ReplyUserImage = model.content_info,
                //ReplyUserName = model.content_info,
            };

            if (userList != null && userList.Count > 0)
            {
                if (info.CommentUserId > 0)
                {
                    var comUser = userList.Where(u => u.id == info.CommentUserId).FirstOrDefault();
                    info.CommentUserName  = UserUtility.GetShowName(comUser.name, comUser.symbol);
                    info.CommentUserImage = comUser.head_image;
                }

                if (info.ReplyUserId > 0)
                {
                    var repUser = userList.Where(u => u.id == info.ReplyUserId).FirstOrDefault();
                    info.ReplyUserName  = UserUtility.GetShowName(repUser.name, repUser.symbol);
                    info.ReplyUserImage = repUser.head_image;
                }
            }

            res.CommentInfo = info;
            if (!isChanged)
            {
                res.CircleLastUpdateTime = GenericUtility.FormatDate2(circleModel.update_time);
            }


            return(res);
        }
Beispiel #3
0
        public static void BindCircleInfos(HWLEntities db, int userId, List <CircleInfo> infos)
        {
            if (infos == null || infos.Count <= 0)
            {
                return;
            }

            List <int>            imageCircleIds = infos.Where(n => CustomerEnumDesc.ImageContentTypes().Contains(n.ContentType)).Select(n => n.CircleId).ToList();
            List <t_circle_image> imageList      = null;

            if (imageCircleIds != null && imageCircleIds.Count > 0)
            {
                imageList = db.t_circle_image.Where(i => imageCircleIds.Contains(i.circle_id)).ToList();
            }
            List <int> circleIds   = infos.Select(n => n.CircleId).ToList();
            var        likeList    = db.t_circle_like.Where(l => circleIds.Contains(l.circle_id) && l.is_delete == false).ToList();
            var        commentList = db.t_circle_comment.Where(c => circleIds.Contains(c.circle_id)).ToList();

            List <int> userIds = infos.Select(u => u.PublishUserId).ToList();

            if (likeList != null && likeList.Count > 0)
            {
                userIds.AddRange(likeList.Select(u => u.like_user_id).ToList());
            }
            if (commentList != null && commentList.Count > 0)
            {
                userIds.AddRange(commentList.Select(u => u.com_user_id).ToList());
                userIds.AddRange(commentList.Select(c => c.reply_user_id).ToList());
            }
            var userList   = db.t_user.Where(i => userIds.Contains(i.id)).Select(i => new { i.id, i.name, i.head_image }).ToList();
            var friendList = db.t_user_friend.Where(f => f.user_id == userId && userIds.Contains(f.friend_user_id)).Select(f => new { f.friend_user_id, f.friend_user_remark }).ToList();

            foreach (var item in infos)
            {
                if (imageList != null && imageList.Count > 0)
                {
                    item.Images = imageList.Where(i => i.circle_id == item.CircleId).Select(i => new ImageInfo()
                    {
                        Url    = i.image_url,
                        Height = i.height,
                        Width  = i.width
                    }).ToList();
                }

                if (userList != null && userList.Count > 0)
                {
                    var user = userList.Where(u => u.id == item.PublishUserId).FirstOrDefault();
                    if (user != null)
                    {
                        string friendRemark = friendList != null?friendList.Where(f => f.friend_user_id == item.PublishUserId).Select(f => f.friend_user_remark).FirstOrDefault() : null;

                        item.PublishUserName  = UserUtility.GetShowName(friendRemark, user.name);
                        item.PublishUserImage = user.head_image;
                    }
                }

                if (likeList != null && likeList.Count > 0)
                {
                    item.IsLiked   = likeList.Where(l => l.circle_id == item.CircleId && l.like_user_id == userId).Select(l => l.id).FirstOrDefault() > 0 ? true : false;
                    item.LikeInfos = likeList.Where(l => l.circle_id == item.CircleId)
                                     .Select(l =>
                    {
                        CircleLikeInfo model = new CircleLikeInfo()
                        {
                            LikeId     = l.id,
                            LikeUserId = l.like_user_id,
                            CircleId   = l.circle_id,
                            LikeTime   = GenericUtility.FormatDate(l.like_time),
                        };
                        if (userList != null && userList.Count > 0)
                        {
                            var likeUser = userList.Where(u => u.id == l.like_user_id).FirstOrDefault();
                            if (likeUser != null)
                            {
                                string friendRemark = friendList != null ? friendList.Where(f => f.friend_user_id == l.like_user_id).Select(f => f.friend_user_remark).FirstOrDefault() : null;
                                model.LikeUserName  = UserUtility.GetShowName(friendRemark, likeUser.name);
                                model.LikeUserImage = likeUser.head_image;
                            }
                        }
                        return(model);
                    }).ToList();
                }

                if (commentList != null && commentList.Count > 0)
                {
                    item.CommentInfos = commentList.Where(c => c.circle_id == item.CircleId)
                                        .Select(c =>
                    {
                        CircleCommentInfo model = new CircleCommentInfo()
                        {
                            CommentId        = c.id,
                            Content          = c.com_content,
                            CircleId         = c.circle_id,
                            CommentTime      = GenericUtility.FormatDate(c.comment_time),
                            CommentUserId    = c.com_user_id,
                            CommentUserImage = null,
                            CommentUserName  = null,
                            ReplyUserId      = c.reply_user_id,
                            ReplyUserName    = null,
                            ReplyUserImage   = null,
                        };
                        if (userList != null && userList.Count > 0)
                        {
                            if (c.com_user_id > 0)
                            {
                                var comUser = userList.Where(u => u.id == c.com_user_id).FirstOrDefault();
                                if (comUser != null)
                                {
                                    string friendRemark    = friendList != null ? friendList.Where(f => f.friend_user_id == c.com_user_id).Select(f => f.friend_user_remark).FirstOrDefault() : null;
                                    model.CommentUserName  = UserUtility.GetShowName(friendRemark, comUser.name);
                                    model.CommentUserImage = comUser.head_image;
                                }
                            }

                            if (c.reply_user_id > 0)
                            {
                                var repUser = userList.Where(u => u.id == c.reply_user_id).FirstOrDefault();
                                if (repUser != null)
                                {
                                    string friendRemark  = friendList != null ? friendList.Where(f => f.friend_user_id == c.reply_user_id).Select(f => f.friend_user_remark).FirstOrDefault() : null;
                                    model.ReplyUserName  = UserUtility.GetShowName(friendRemark, repUser.name);
                                    model.ReplyUserImage = repUser.head_image;
                                }
                            }
                        }
                        return(model);
                    }).ToList();
                }
            }
        }