public async Task RemoveFromRoom(string roomName) { // Retrieve room. var room = await db.Rooms.FindAsync(roomName); // var test = await db.Rooms.FirstOrDefaultAsync(x=> x.) if (room != null) { var user = new User() { UserName = Context.User.Identity.Name }; var newUser = new UserRooms() { User = user }; db.User.Attach(user); room.Users.Remove(newUser); db.SaveChanges(); // Groups.Remove(Context.ConnectionId, roomName); await Groups.RemoveFromGroupAsync(Context.ConnectionId, roomName); } }
public async Task AddToRoom(string roomName) { // var username = _httpContextAccessor.HttpContext.User?.Claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value; // Retrieve room. var room = await db.Rooms.FirstOrDefaultAsync(x => x.RoomName == roomName); if (room != null) { // var user = new User() { UserName =username }; var user = new User() { UserName = Context.User.Identity.Name }; var newUser = new UserRooms() { User = user }; db.User.Attach(user); room.Users.Add(newUser); // room.Users.Add(user); db.SaveChanges(); await Groups.AddToGroupAsync(Context.ConnectionId, roomName); } }