Esempio n. 1
0
        public bool UpdateMessageReadState()
        {
            int accountId  = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0);
            var repository = _unitOfWork.GetRepository <m_Message>();
            int count      = _unitOfWork.DbContext.MangoUpdate <m_Message>(q => q.IsRead == true, q => q.AccountId == accountId && q.IsRead == false);

            if (count > 0)
            {
                //消息推送
                var    messageCount = repository.Query().Where(q => q.AccountId == accountId && q.IsRead == false).Select(q => q.MessageId).Count();
                string sendMsg      = $"{accountId}#{messageCount}";
                //发送消息
                _rabbitMQService.BasicPublish("message", System.Text.Encoding.UTF8.GetBytes(sendMsg));
            }
            return(true);
        }
Esempio n. 2
0
        public IActionResult Theme(Models.ThemePlusRequestModel requestModel)
        {
            int accountId         = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0);
            var messageRepository = _unitOfWork.GetRepository <m_Message>();
            var plusRepository    = _unitOfWork.GetRepository <m_AccountPlusRecords>();
            var plusCount         = plusRepository.Query().Where(q => q.AccountId == accountId && q.ObjectId == requestModel.ThemeId && q.RecordsType == 10).Select(q => q.RecordsId).Count();

            int resultCount = 0;

            using (var tran = _unitOfWork.BeginTransaction())
            {
                try
                {
                    if (plusCount > 0)
                    {
                        //存在则撤回点赞记录
                        _unitOfWork.DbContext.MangoRemove <m_AccountPlusRecords>(q => q.ObjectId == requestModel.ThemeId && q.AccountId == accountId && q.RecordsType == 10);
                        //
                        _unitOfWork.DbContext.MangoUpdate <Entity.m_DocsTheme>(q => q.PlusCount == q.PlusCount - 1, q => q.ThemeId == requestModel.ThemeId);
                        resultCount = -1;
                    }
                    else
                    {
                        //添加新点赞记录
                        m_AccountPlusRecords model = new m_AccountPlusRecords();
                        model.ObjectId    = requestModel.ThemeId;
                        model.AppendTime  = DateTime.Now;
                        model.RecordsType = 10;
                        model.AccountId   = accountId;
                        plusRepository.Insert(model);
                        //
                        _unitOfWork.DbContext.MangoUpdate <Entity.m_DocsTheme>(q => q.PlusCount == q.PlusCount + 1, q => q.ThemeId == requestModel.ThemeId);
                        //
                        //消息通知
                        m_Message message = new m_Message();
                        message.AppendAccountId = accountId;
                        message.Contents        = Core.Common.MessageHtml.GetMessageContent(HttpContext.Session.GetString("NickName"), requestModel.ThemeId, requestModel.Title, 10, 0);
                        message.IsRead          = false;
                        message.MessageType     = 10;
                        message.ObjectId        = requestModel.ThemeId;
                        message.PostTime        = DateTime.Now;
                        message.AccountId       = requestModel.ToAccountId;

                        messageRepository.Insert(message);
                        resultCount = 1;
                    }
                    _unitOfWork.SaveChanges();
                    tran.Commit();
                }
                catch
                {
                    tran.Rollback();
                    resultCount = 0;
                }
            }
            if (resultCount > 0)
            {
                var    messageCount = messageRepository.Query().Where(q => q.AccountId == requestModel.ToAccountId && q.IsRead == false).Select(q => q.MessageId).Count();
                string sendMsg      = $"{accountId}#{messageCount}";
                //发送消息
                _rabbitMQService.BasicPublish("message", System.Text.Encoding.UTF8.GetBytes(sendMsg));
            }
            return(APIReturnMethod.ReturnSuccess(resultCount));
        }