Пример #1
0
        public async Task BanAsync(string userId, string reason)
        {
            await _userService.BanAsync(new User { Id = userId }, reason);

            await _notificationService.NotifyAsync(userId, "Ban", new BanNotificationSource()
            {
                Reason = reason
            });

            await _hubContext.Clients.Clients(_userConnectionService.GetUserConnections(userId)).SendAsync("ban", reason);
        }
Пример #2
0
        public MessageDto SendMessage(JwtSecurityToken token, string chatId, string type, IMessageSource message)
        {
            var chat = _directChatGR.GetDbSet().Where(x => x.Id == chatId && (x.User1Id == token.Subject || x.User2Id == token.Subject)).FirstOrDefault();

            if (chat == null)
            {
                throw new ClientException("inc-chatid");
            }

            var msg = _directMessageGR.Create(new DirectMessage
            {
                ChatId       = chatId,
                SenderId     = token.Subject,
                Type         = type,
                Date         = DateTime.Now,
                Base64Source = ObjectToBase64String(message)
            });

            chat.Read = chat.User1Id == token.Subject ? 2 : 1;
            _directChatGR.Update(chat);

            var ntf = new ChatMessageSource
            {
                Id           = msg.Id,
                Type         = msg.Type,
                Base64Source = msg.Base64Source,
                Date         = msg.Date,
                Sender       = _userService.GetShortDto(token.Subject)
            };

            _dataBaseNotificationService.NotifyAsync(chat.User1Id == token.Subject ? chat.User2Id : chat.User1Id, "newChatMessage", ntf);

            var msgDto = new NewMessageSource
            {
                Id           = msg.Id,
                Type         = msg.Type,
                Base64Source = msg.Base64Source,
                Date         = msg.Date,
                Sender       = ntf.Sender
            };

            _chatEventService.SendNewMessageEvent(token.Subject, chatId, msgDto);

            return(msgDto);
        }
Пример #3
0
        public async Task <ActionResult <IEnumerable <string> > > Get()
        {
            await _dataBaseNotificationManager.NotifyAsync(_userGR.GetAll((x) => x.Login == "admin").First().Id, "test", new MessageNotificationSource { Message = "Baboola" });

            return(new string[] { _webHostEnvironment.ContentRootPath, _webHostEnvironment.WebRootPath });
        }