Beispiel #1
0
        /// <summary>
        /// 取得留言內頁資訊
        /// </summary>
        /// <param name="token">使用者代碼</param>
        /// <param name="outerKey">留言/回覆代碼</param>
        /// <param name="maxResult">顯示回覆列表筆數 - 預設10筆</param>
        /// <returns></returns>
        public DiscussionCommentDetail GetCommentDetail(Guid token, string outerKey, int?maxResult = 10)
        {
            var db     = _uow.DbContext;
            var result = new DiscussionCommentDetail();

            result.Replys         = new List <DiscussionMessage>();
            discussionLikeService = new DiscussionFuncLike();
            var msgEventId = Service.Utility.OuterKeyHelper.CheckOuterKey(outerKey);
            //用於取得msgEventId的留言資訊
            var msgInfo = db.ActModuleMessage.FirstOrDefault(t => t.OuterKey == msgEventId);
            //如果是回覆則取得該回覆的留言資訊 | 若是留言則直接存取留言資訊
            var commentInfo = (db.ActModuleMessage.FirstOrDefault(t => t.OuterKey == msgEventId && t.Parent != null)) != null?db.ActModuleMessage.Find(db.ActModuleMessage.FirstOrDefault(t => t.OuterKey == msgEventId).Parent) : msgInfo;

            if (commentInfo != null)
            {
                var commentCreatorInfo = new MemberService().UserIdToAccount(commentInfo.CreateUser.Value);
                //  var commentCreatorInfo = new Service.MemberService().GetPhotoMember(db.Members.Find(commentInfo.CreateUser).Account);
                result.Comment = new DiscussionMessage()
                {
                    CreateTime     = commentInfo.Created.Utc.Value.ToLocalTime(),
                    CreatorAccount = commentCreatorInfo.Account,
                    CreatorName    = commentCreatorInfo.Name,
                    CreatorPhoto   = commentCreatorInfo.Photo,
                    Message        = commentInfo.Content,
                    EventId        = commentInfo.OuterKey,
                    Parent         = commentInfo.Parent
                };

                var commentPhoto = GetDiscussionMessageFileByMessageId(commentInfo.Id);
                result.Comment.Photos = commentPhoto != null ? commentPhoto : new List <FileStorageViewModel>();

                var commentLikeArray = discussionLikeService.GetLikeArrayByEventId(commentInfo.OuterKey);
                result.Comment.LikeArray = commentLikeArray != null?commentLikeArray.ToArray() : null;

                var replys = db.ActModuleMessage.Where(t => t.Parent == commentInfo.Id).OrderByDescending(t => t.Created.Utc).ToList();
                result.Comment.ReplyCount = replys.FirstOrDefault() != null?replys.Count() : 0;

                result.CommentCount = replys.FirstOrDefault() != null?replys.Count() : 0;



                //判斷現在是否要查留言內頁的資訊
                if (msgInfo.Parent.HasValue)
                {
                    //篩選該msg以後的留言[包含]
                    replys = replys.Where(t => t.Id >= msgInfo.Id).ToList();
                    replys.Reverse();
                    result.OlderCount = result.CommentCount - replys.Count();
                    replys            = replys.Take(maxResult.Value).ToList();
                }
                else
                {
                    result.OlderCount = replys.Count() > maxResult.Value ? replys.Count() - maxResult.Value : 0;
                    replys            = replys.Take(maxResult.Value).ToList();
                    replys.Reverse();
                }

                foreach (var reply in replys)
                {
                    var replyCreatorInfo = new MemberService().UserIdToAccount(reply.CreateUser.Value);
                    //   var replyCreatorInfo = new Service.MemberService().GetPhotoMember(db.Members.Find(reply.CreateUser).Account);
                    var tempReply = new DiscussionMessage()
                    {
                        CreateTime     = reply.Created.Utc.Value.ToLocalTime(),
                        CreatorAccount = replyCreatorInfo.Account,
                        CreatorName    = replyCreatorInfo.Name,
                        CreatorPhoto   = replyCreatorInfo.Photo,
                        Message        = reply.Content,
                        EventId        = reply.OuterKey,
                        Parent         = reply.Parent
                    };
                    var replyPhoto = GetDiscussionMessageFileByMessageId(reply.Id);
                    tempReply.Photos = replyPhoto != null ? replyPhoto : new List <FileStorageViewModel>();

                    var likeArray = discussionLikeService.GetLikeArrayByEventId(reply.OuterKey);
                    tempReply.LikeArray = likeArray != null?likeArray.ToArray() : null;

                    if (reply.TagActModuleMessageId != null && reply.TagActModuleMessageId != 0)
                    {
                        var replyInfo = db.ActModuleMessage.Find(reply.TagActModuleMessageId);
                        if (replyInfo != null)
                        {
                            var replyMemberInfo = db.Members.Find(replyInfo.CreateUser);
                            tempReply.ReplyOuterKey = reply.OuterKey.ToString();
                            tempReply.ReplyName     = replyMemberInfo.Name;
                        }
                    }
                    tempReply.ReplyCount = db.ActModuleMessage.FirstOrDefault(t => t.Parent == reply.Id) != null?db.ActModuleMessage.Where(t => t.Parent == reply.Id).Count() : 0;

                    result.Replys.Add(tempReply);
                }
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 取得主題討論底下的留言列表
        /// </summary>
        /// <param name="eventId"></param>
        /// <param name="msgEventId"></param>
        /// <param name="isLoadNewer"></param>
        /// <returns></returns>
        public List <DiscussionMessage> GetDiscussionMsgList(Guid eventId, Guid msgEventId, bool?isLoadNewer = true)
        {
            var result = new List <DiscussionMessage>();
            var db     = _uow.DbContext;
            //預設查詢主題討論的留言列表
            var sqlData = from amm in db.ActModuleMessage
                          join a in db.Activitys on amm.ActivityId equals a.Id
                          where a.OuterKey == eventId
                          orderby amm.Created.Utc
                          select amm;

            if (sqlData.FirstOrDefault() != null)
            {
                discussionLikeService = new DiscussionFuncLike();
                //查出該msg的資訊
                var setMsgInfo = (sqlData.FirstOrDefault(t => t.OuterKey == msgEventId && t.Parent != null)) != null?sqlData.FirstOrDefault(t => t.Id == (sqlData.FirstOrDefault(tt => tt.OuterKey == msgEventId)).Parent) : sqlData.FirstOrDefault(t => t.OuterKey == msgEventId);

                if (setMsgInfo != null)
                {
                    sqlData = sqlData.Where(t => t.Parent == null || t.Parent == 0);
                    //查新的
                    if (isLoadNewer.Value)
                    {
                        //篩選該msg以後的留言[包含]
                        sqlData = sqlData.Where(t => t.Id >= setMsgInfo.Id);
                    }
                    //查舊的
                    else
                    {
                        sqlData = sqlData.Where(t => t.Id < setMsgInfo.Id);
                    }
                }
                //塞資料
                foreach (var msg in sqlData)
                {
                    //取得留言者資訊
                    var memberInfo = new MemberService().UserIdToAccount(msg.CreateUser.Value);
                    // var memberInfo = new iThink.Service.Service.MemberService().GetPhotoMember(db.Members.Find(msg.CreateUser.Value).Account);
                    //取得留言檔案資訊
                    var msgFile = GetDiscussionMessageFileByMessageId(msg.Id);
                    var tempMsg = new DiscussionMessage();
                    tempMsg.Id         = msg.Id;
                    tempMsg.CreateTime = msg.Created.Local.Value;
                    tempMsg.LikeArray  = discussionLikeService.GetLikeArrayByEventId(msg.OuterKey).ToArray();
                    if (msgFile != null)
                    {
                        tempMsg.Photos = msgFile;
                    }
                    else
                    {
                        tempMsg.Photos = new List <FileStorageViewModel>();
                    }
                    tempMsg.Message = msg.Content;
                    tempMsg.EventId = msg.OuterKey;
                    tempMsg.Parent  = msg.Parent;
                    if (memberInfo != null)
                    {
                        tempMsg.CreatorAccount = memberInfo.Account;
                        tempMsg.CreatorName    = memberInfo.Name;
                        tempMsg.CreatorPhoto   = memberInfo.Photo;
                    }
                    //是否有tag某篇留言
                    if (msg.TagActModuleMessageId != null && msg.TagActModuleMessageId != 0)
                    {
                        var replyInfo = db.ActModuleMessage.Find(msg.TagActModuleMessageId);
                        if (replyInfo != null)
                        {
                            var replyMemberInfo = db.Members.Find(replyInfo.CreateUser);
                            tempMsg.ReplyOuterKey = replyInfo.OuterKey.ToString();
                            tempMsg.ReplyName     = replyMemberInfo.Name;
                        }
                    }
                    //查詢回覆數量
                    tempMsg.ReplyCount = db.ActModuleMessage.FirstOrDefault(t => t.Parent == msg.Id) != null?db.ActModuleMessage.Where(t => t.Parent == msg.Id).Count() : 0;

                    result.Add(tempMsg);
                }
            }
            return(result);
        }