Esempio n. 1
0
        /// <summary>
        /// 回傳主題討論或留言的結果
        /// </summary>
        /// <param name="memberInfo"></param>
        /// <param name="eventId"></param>
        /// <param name="commentOuterKey"></param>
        /// <returns></returns>
        private DiscussionUpdateLikeInfo CancelLike(Member memberInfo, Guid eventId, string commentOuterKey)
        {
            var result = new DiscussionUpdateLikeInfo();

            //針對留言按讚
            if (commentOuterKey != null && commentOuterKey != string.Empty)
            {
                var db             = _uow.DbContext;
                var commentEventId = Utility.OuterKeyHelper.CheckOuterKey(commentOuterKey);
                if (commentEventId.HasValue == false)
                {
                    return(null);
                }
                //處理按讚資訊
                UnLikeDbProxy(memberInfo, commentEventId.Value);
                var commentInfo = db.ActModuleMessage.FirstOrDefault(t => t.OuterKey == commentEventId.Value);
                //判斷是否為回覆[ true 是回覆 | false 是留言]
                var checkReply = (commentInfo.Parent != null && commentInfo.Parent != 0) ? true : false;
                result.MessageEnum     = checkReply ? 3 : 2;
                result.CommentOuterKey = checkReply ?
                                         Utility.OuterKeyHelper.GuidToPageToken(db.ActModuleMessage.FirstOrDefault(t => t.Id == commentInfo.Parent).OuterKey) :
                                         Utility.OuterKeyHelper.GuidToPageToken(commentEventId.Value);
                result.ReplyOuterKey = checkReply ? commentOuterKey.ToString() : null;
            }
            //針對主題討論按讚
            else
            {
                UnLikeDbProxy(memberInfo, eventId);
                result.MessageEnum = 1;
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 變更按讚狀態
        /// </summary>
        /// <param name="memberInfo">按讚者資訊</param>
        /// <param name="activityOuterKey">主題討論代碼</param>
        /// <param name="commentOuterKey">留言代碼 / 回覆代碼</param>
        /// <returns></returns>
        public DiscussionUpdateLikeInfo SwitchLike(Member memberInfo, string activityOuterKey, string commentOuterKey)
        {
            lock (lockObject)
            {
                var db     = _uow.DbContext;
                var result = new DiscussionUpdateLikeInfo();
                //主題討論的代碼
                var eventId = Utility.OuterKeyHelper.CheckOuterKey(activityOuterKey);
                if (eventId.HasValue == false)
                {
                    return(null);
                }
                //查出按讚列表
                var checkLikeArray = (commentOuterKey != null && commentOuterKey != string.Empty) ? GetLikeArrayByOuterKey(commentOuterKey) : GetLikeArrayByEventId(eventId.Value);
                result.ActivityOuterKey = activityOuterKey;

                //要按讚
                if (checkLikeArray.FirstOrDefault(t => t == memberInfo.Account) == null)
                {
                    var proxy = DoLike(memberInfo, eventId.Value, commentOuterKey);
                    if (proxy != null)
                    {
                        result.MessageEnum     = proxy.MessageEnum;
                        result.CommentOuterKey = proxy.CommentOuterKey;
                        result.ReplyOuterKey   = proxy.ReplyOuterKey;
                        result.IsLike          = true;
                        //加按讚者
                        checkLikeArray.Add(memberInfo.Account);
                    }
                }
                //取消讚
                else
                {
                    var proxy = CancelLike(memberInfo, eventId.Value, commentOuterKey);
                    if (proxy != null)
                    {
                        var arrayProxy = checkLikeArray.ToList();
                        arrayProxy.Remove(memberInfo.Account.ToLower());
                        //去掉按讚者
                        checkLikeArray         = arrayProxy;
                        result.MessageEnum     = proxy.MessageEnum;
                        result.CommentOuterKey = proxy.CommentOuterKey;
                        result.ReplyOuterKey   = proxy.ReplyOuterKey;
                        result.IsLike          = false;
                    }
                }
                db.SaveChanges();
                result.LikeArray = checkLikeArray.ToArray();
                return(result);
            }
        }