示例#1
0
        public void AddChatRoomToDatabase()
        {
            // Arrange
            ChatRoom room = new ChatRoom() { ChatRoomName = "ASDFE", HasAdminUser = true, Status = 1 };

            // Act
            _service.AddChatRoom(room);
            var rooms = _service.GetActiveChatRooms();

            // Assert
            Assert.IsNotNull(rooms);
        }
示例#2
0
文件: ChatHub.cs 项目: jascenci/Chat
        // Connect/Create Agent ChatUser and add to a ChatRoom and SignalR Group
        public ChatClientUser ConnectUser(string username)
        {
            var OnlineUsers = _service.GetOnlineUsers();

            if (OnlineUsers.Count() > 1)
            {
                string roomName = RandomString(5);
                JoinGroup(roomName);

                ChatClientUser user = new ChatClientUser() { userName = username, roomName = roomName, isUserAllowed = true, ConnectionId = Context.ConnectionId };
                ChatRoom room = new ChatRoom();

                room.ChatUserId = user.userName;

                room.StartTime = GetLocalTime();
                //room.StartTime = DateTime.Now;
                room.Status = 0;
                room.ActiveUserCount = 1;
                room.ChatRoomName = roomName;
                room.HasAdminUser = false;

                activeUsers.Add(user);

                // Save ChatRoom to Repo
                _service.AddChatRoom(room);

                // This adds the new chat room to the admin chat lobby
                Clients.Group("adminGroup").addActiveRoom(room, user);

                RoomFeedVM roomFeed = new RoomFeedVM();

                if (room.HasAdminUser == true)
                { roomFeed.BeingHelped = "Yes"; }
                else { roomFeed.BeingHelped = "No"; }
                roomFeed.ClientId = room.ChatUserId;
                roomFeed.HelperName = "";
                roomFeed.RoomName = room.ChatRoomName;
                roomFeed.StartTime = room.StartTime;
                roomFeed.UsersInRoom = room.ActiveUserCount;

                Clients.All.addRoom(roomFeed);

                return user;
            }
            else
            {
                return new ChatClientUser { userName = username, isUserAllowed = false };
            }
        }
示例#3
0
 public void AddChatRoom(ChatRoom room)
 {
     _repo.AddNewChatRoom(room);
 }
示例#4
0
 public void UpdateChatRoom(ChatRoom room)
 {
     _repo.UpdateChatRoom(room);
 }
示例#5
0
 public void AddNewChatRoom(ChatRoom room)
 {
     _dbContext.ChatRooms.Add(room);
     _dbContext.SaveChanges();
 }
示例#6
0
 public void UpdateChatRoom(ChatRoom room)
 {
     _dbContext.Entry(room).State = EntityState.Modified;
     _dbContext.SaveChanges();
 }