Example #1
0
        public async Task CreateChatRoom(CreateChatRoomRequest roomRequest)
        {
            try
            {
                var room = _chatRoomService.CreateChatRoom(roomRequest.UserCreatorId, roomRequest.UserInvitedId, roomRequest.Name);

                var result = _mapper.Map <ChatRoomModel>(room);

                // create group
                await this.Groups.AddToGroupAsync(this.Context.ConnectionId, room.Id.ToString());

                //3. return room id to those tow users
                await this.Clients.Caller.ChatRoomCreated(result);

                var invitedUserConnected = _userConnectionService.GetConnectionForUser(roomRequest.UserInvitedId);
                if (invitedUserConnected != null)
                {
                    await this.Groups.AddToGroupAsync(invitedUserConnected.ConnectionId, room.Id.ToString());

                    await this.Clients.Client(invitedUserConnected.ConnectionId).ChatRoomCreated(result);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }