Ejemplo n.º 1
0
        public ChatRoom CreateRoom(int userId)
        {
            var sessionUser = _userService.GetSessionUser();
            var targetUser  = _userService.GetUserById(userId);
            var users       = new List <User> {
                sessionUser, targetUser
            };

            //fix creation of many rooms
            var dbRoom = GetRoomForUsers(sessionUser, targetUser);

            if (dbRoom is null)
            {
                var chatRoom = new ChatRoom()
                {
                    Users = users,
                    Name  = targetUser.FirstName,
                };

                _chatRepository.AddRoom(chatRoom);

                return(chatRoom);
            }

            return(dbRoom);
        }
Ejemplo n.º 2
0
        public void AddRoom(Room model)
        {
            var id = _chatRepository.AddRoom(model);

            model.Id = id;
            var result = ChatController.RenderViewToString(ControllerContext, "_Room", model);

            ChatHub.AddRoom(result);
        }
Ejemplo n.º 3
0
        public async Task <ChatRoomDto> CreateChatRoom(ChatRoomDto room)
        {
            var cRoom = _mapper.Map <ChatRoom>(room);

            cRoom.Id = Guid.NewGuid();
            bool result = await _repo.AddRoom(cRoom);

            if (result)
            {
                return(room = _mapper.Map <ChatRoomDto>(cRoom));
            }

            return(null);
        }