public Task Connect() { UserAccount ua = new UserAccount(Context.User.Identity.Name); ChatRoomUser cru = new ChatRoomUser(); cru.GetChatRoomUserByUserAccountID(ua.UserAccountID); if (cru.ChatRoomUserID == 0) { cru.CreatedByUserID = ua.UserAccountID; cru.ConnectionCode = Context.ConnectionId; cru.Create(); } else { cru.ConnectionCode = Context.ConnectionId; cru.UpdatedByUserID = ua.UserAccountID; cru.Update(); } Send(@"<i style=""color:yellow;font-size:10px;font-style: italic;"">CONNECTION OPENED</i>", ua.UserAccountID); return Clients.joined(Context.ConnectionId, DateTime.UtcNow.ToString()); }
public void Connect(string userName) { MembershipUser mu = MembershipWrapper.GetUser(); string id = Context.ConnectionId; if (ConnectedUsers.Count(x => x.ConnectionId == id) != 0) return; ConnectedUsers.Add(new UserDetail {ConnectionId = id, UserName = userName}); if (mu != null) { var enterRoom = new ChatRoomUser(); enterRoom.GetChatRoomUserByUserAccountID(Convert.ToInt32(mu.ProviderUserKey)); if (enterRoom.RoomID == 0) { enterRoom = new ChatRoomUser { CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey), ConnectionCode = id }; enterRoom.Create(); } else { enterRoom.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey); enterRoom.ConnectionCode = id; enterRoom.Update(); } } // send to caller Clients.Caller.onConnected(id, userName, ConnectedUsers, CurrentMessage); // send to all except caller client Clients.AllExcept(id).onNewUserConnected(id, userName); }