46 Private Sub GetLoggedInUsers()
47 Dim db As LinqChatDataContext = New LinqChatDataContext()
48
49 ' let's check if this authenticated user exist in the
50 ' LoggedInUser table (means user is logged-in to this room)
51 Dim user = (From u In db.LoggedInUsers _
52 Where u.UserID = Convert.ToInt32(Session("ChatUserID")) _
53 And u.RoomID = Convert.ToInt32(lblRoomId.Text) _
54 Select u).SingleOrDefault()
55
56 ' if user does not exist in the LoggedInUser table
57 ' then let's add/insert the user to the table
58 If user Is Nothing Then
59 Dim loggedInUser As LoggedInUser = New LoggedInUser()
60 loggedInUser.UserID = Convert.ToInt32(Session("ChatUserID"))
61 loggedInUser.RoomID = Convert.ToInt32(lblRoomId.Text)
62 db.LoggedInUsers.InsertOnSubmit(loggedInUser)
63 db.SubmitChanges()
64 End If
65
66 Dim userIcon As String
67 Dim sb As StringBuilder = New StringBuilder()
68
69 ' get all logged in users to this room
70 Dim loggedInUsers = From l In db.LoggedInUsers _
71 Where l.RoomID = Convert.ToInt32(lblRoomId.Text) _
72 Select l
73
74 For Each loggedInUser In loggedInUsers
75 ' show user icon based on sex
76 If loggedInUser.User.Sex.ToString().ToLower() = "m" Then
77 userIcon = "<img src='Images/manIcon.gif' style='vertical-align:middle' alt=''> "
78 Else
79 userIcon = "<img src='Images/womanIcon.gif' style='vertical-align:middle' alt=''> "
80 End If
81
82 If (Not loggedInUser.User.Username = Session("ChatUsername").ToString()) Then
83 sb.Append(userIcon + "<a href=#>" + loggedInUser.User.Username + "</a><br>")
84 Else
85 sb.Append(userIcon + "<b>" + loggedInUser.User.Username + "</b><br>")
86 End If
87 Next
88
89 ' holds the names of the users shown in the chatroom
90 litUsers.Text = sb.ToString()
91 End Sub