Esempio n. 1
0
        public int UpdateMsgStatus(SubmitUnReadMsgIdList submitData)
        {
            //  Console.WriteLine("DB: updateMsg start");
            var op = Db.Updateable <EMsgInfo_Praize>()
                     .SetColumns(m => new EMsgInfo_Praize
            {
                NotificationStatus = submitData.targetStatus
            })
                     .Where(m => m.ReceiveUserId == submitData.userId && submitData.msgIdList.Contains(m.Id) &&
                            m.NotificationStatus != NotificationStatus.read);

            try
            {
                var r = op.ExecuteCommand();
                //  Console.WriteLine("DB: updateMsg end");
                return(r);
            }
            catch (Exception ex)
            {
                var m = ex;
                throw ex;
            }

            // return
        }
        //更新消息到已读
        private void updateMsgToRead(SubmitUnReadMsgIdList submitData)
        {
            //   ResultNormal result = new ResultNormal();
            if (string.IsNullOrEmpty(submitData.userId))
            {
                throw new CCException("非法请求");
            }

            var msgList = submitData.msgIdList;

            if (msgList == null || msgList.Count <= 0)
            {
                throw new Exception("[MessgeServices] updateMsgToRead:入参没有信息更新");
            }

            var transResult = _msgReplyRepository.Db.Ado.UseTran(() =>
            {
                int num = 0;
                //更新已读消息
                switch (submitData.notificationType)
                {
                case NotificationType.praize:
                    num = _msgPraizeRepository.UpdateMsgStatus(submitData);
                    break;

                case NotificationType.comment:
                    num = _msgCommentResRepository.UpdateMsgStatus(submitData);
                    break;

                case NotificationType.reply:
                    num = _msgReplyRepository.UpdateMsgStatus(submitData);
                    break;

                case NotificationType.system:
                    num = _msgSystemRepository.UpdateMsgStatus(submitData);
                    break;
                }
                if (num > 0)
                {
                    //概况更新为已读
                    _msgInfoOverviewRepository.UpdateNotificateToRead(submitData.notificationType, submitData.userId, num);
                }
            });

            if (!transResult.IsSuccess)
            {
                throw new Exception(transResult.ErrorMessage);
                // result.ErrorMsg = transResult.ErrorMessage;
            }
        }
        //异步方法 查询后获取未读消息转成已读
        public void Async_MsgToReadAfterQuery(QMsgUser query,
                                              List <VueMsgInfoNotification> queryResult = null,
                                              List <VueSystemNotification> systemResult = null //由于系统消息对象不同,暂时只能这样写。。。
                                              )
        {
            Task.Run(() =>
            {
                try
                {
                    SubmitUnReadMsgIdList unReadList = new SubmitUnReadMsgIdList();
                    if (query.notificationType == NotificationType.system)
                    {
                        foreach (var msg in systemResult)
                        {
                            if (msg.NotificationStatus != NotificationStatus.read)
                            {
                                unReadList.msgIdList.Add(msg.msgId);
                            }
                        }
                    }
                    else
                    {
                        foreach (var msg in queryResult)
                        {
                            if (msg.NotificationStatus != NotificationStatus.read)
                            {
                                unReadList.msgIdList.Add(msg.msgId);
                            }
                        }
                    }

                    if (unReadList.msgIdList.Count > 0)
                    {
                        unReadList.notificationType = query.notificationType;
                        unReadList.targetStatus     = NotificationStatus.read;
                        unReadList.userId           = query.userId;


                        this.updateMsgToRead(unReadList);
                    }
                }
                catch (Exception ex)
                {
                    NLogUtil.cc_ErrorTxt("[MessageService]MsgToReadAfterQuery_Async:" + ex.Message);
                }
            });
        }
        public int UpdateMsgStatus(SubmitUnReadMsgIdList submitData)
        {
            var op = Db.Updateable <EMsgInfo_ReplyRes>()
                     .SetColumns(m => new EMsgInfo_ReplyRes
            {
                NotificationStatus = submitData.targetStatus
            })
                     .Where(m => m.ReceiveUserId == submitData.userId && submitData.msgIdList.Contains(m.Id) &&
                            m.NotificationStatus != NotificationStatus.read);

            try
            {
                var r = op.ExecuteCommand();

                return(r);
            }
            catch (Exception ex)
            {
                var m = ex;
                throw ex;
            }
        }