コード例 #1
0
        private EMsgInfo_ReplyRes replyToMsg(MsgSubmitReply msgSubmitReply, ResSimple resSimple)
        {
            var       submit    = msgSubmitReply.SubmitReply;
            EUserInfo ownerInfo = null;

            if (submit.replyId < 0) //接受者--回复评论的人
            {
                ownerInfo = _commentRepository.getCommentAutherId(submit.commentId);
            }
            else //接受者--回复回复的人
            {
                ownerInfo = _commentReplyRepository.getReplyAutherId(submit.replyId);
            }

            if (ownerInfo == null)
            {
                throw new Exception("[MessageServices]replyToMsg:没有找到通知者用户Id");
            }

            EMsgInfo_ReplyRes msg = new EMsgInfo_ReplyRes
            {
                CreatedDateTime = DateTime.Now,
                //   CommentId = msgSubmitComment.CommentId,
                // NotificationStatus = NotificationStatus.created,
                CommentId      = submit.commentId,
                ReplyId        = msgSubmitReply.ReplyId,
                ReplyReplyId   = submit.replyId,
                resCode        = resSimple.Code,
                SendUserId     = submit.userId,
                SendName       = submit.userName,
                SendHeaderUrl  = submit.userHeaderUrl,
                ReceiveUserId  = ownerInfo.Id,
                ReceiveContent = submit.content,
            };

            return(msg);
        }
コード例 #2
0
        /// <summary>
        /// 创建回复消息
        /// </summary>
        /// <param name="msgSubmitReply"></param>
        public void CreateNotification_Reply(MsgSubmitReply msgSubmitReply)
        {
            var submit = msgSubmitReply.SubmitReply;

            //没有新的回复需要通知
            if (msgSubmitReply.ReplyId <= 0)
            {
                return;
            }

            if (string.IsNullOrEmpty(submit.userId))
            {
                throw new CCException("非法人员 userId is null ");
            }
            if (submit.commentId < 0)
            {
                throw new CCException("commentId is null");
            }

            //检查消息内容
            var res = _resourceReponsitory.getSimpleByCommentId(submit.commentId);

            if (res == null)
            {
                throw new Exception("消息服务[CreateNotification_Reply]:没有找到资源");
            }

            EMsgContent_ReplyRes existContent = _msgReplyRepository.GetContentReplyRes_Sync(res.Code);

            if (existContent == null) //不存在
            {
                //新内容
                existContent    = replyToContent(msgSubmitReply, res);
                existContent.Id = _msgReplyRepository.AddContentReplyRes_Sync(existContent);
            }
            EMsgInfo_ReplyRes msg = replyToMsg(msgSubmitReply, res);

            if (msg == null)
            {
                return;
            }

            // //检查发送者和接受者是否同一人
            if (msg.ReceiveUserId == msg.SendUserId)
            {
                return;
            }

            var transResult = _msgReplyRepository.Db.Ado.UseTran(() =>
            {
                //新消息
                _msgReplyRepository.AddNoIdentity_Sync(msg);
                //总数
                _msgInfoOverviewRepository.UpdateNotificateToUnRead(NotificationType.reply, msg.ReceiveUserId);
            });

            if (!transResult.IsSuccess)
            {
                throw new Exception(transResult.ErrorMessage);
            }
        }