public async Task AddChatRoom(string roomName)
        {
            var chatRoom = new ChatRoom()
            {
                Name = roomName
            };

            await _chatRoomService.AddChatRoomAsync(chatRoom);

            await Clients.All.SendAsync("NewRoom", roomName, chatRoom.Id);
        }
Beispiel #2
0
        public async System.Threading.Tasks.Task CreateChatRoomAfterFirstMessageAsync([FromBody] CreateChatRoomAndSendFirstMessageDTO cht)
        {
            ChatRoom chatRoom = (await chatRoomRepo.GetAsync(ch =>
                                                             (ch.CreatorId == cht.creatorId && ch.SecondUserId == cht.secondUserId) ||
                                                             (ch.CreatorId == cht.secondUserId && ch.SecondUserId == cht.creatorId)
                                                             )).FirstOrDefault();

            if (chatRoom != null)
            {
                Message msg = new Message();
                msg.Content = cht.message;
                foreach (var ch in msg.Content)
                {
                    if (char.IsWhiteSpace(ch))
                    {
                        continue;
                    }
                    await _messageService.AddMessageToRoomAsync(chatRoom.Id, msg, cht.creatorId);
                }
            }
            else
            {
                ChatRoom newChatRoom = new ChatRoom();
                newChatRoom.CreatorId    = cht.creatorId;
                newChatRoom.SecondUserId = cht.secondUserId;
                await _chatRoomService.AddChatRoomAsync(newChatRoom);

                int chId = (await chatRoomRepo.GetAsync(ch => ch.CreatorId == cht.creatorId && ch.SecondUserId == cht.secondUserId)).FirstOrDefault().Id;

                Message msg = new Message();
                msg.Content = cht.message;
                foreach (var ch in msg.Content)
                {
                    if (char.IsWhiteSpace(ch))
                    {
                        continue;
                    }
                    await _messageService.AddMessageToRoomAsync(chId, msg, cht.creatorId);
                }
            }
        }
 public async void Post([FromBody] ChatRoom chatRoom)
 {
     await _chatRoomService.AddChatRoomAsync(chatRoom);
 }