GetConnectionRecordRoomsByUserId() public method

public GetConnectionRecordRoomsByUserId ( int userId ) : IEnumerable
userId int
return IEnumerable
Example #1
0
        //TODO: on connection, reload rooms for user?
        public Task Join()
        {
            int moduleId = Convert.ToInt32(Clients.Caller.moduleid);

            var settingsDefault = new Guid(Clients.Caller.defaultRoomId);

            if (DefaultRoomId != settingsDefault)
            {
                DefaultRoomId = settingsDefault;
            }

            //get list of previously connected (not departed) rooms
            var crrc = new ConnectionRecordRoomController();
            var rc   = new RoomController();

            IEnumerable <Room> myRooms = null;

            //don't do this if we've got a private room loaded.
            if (Convert.ToInt32(Clients.Caller.userid) > 0)
            {
                myRooms = crrc.GetConnectionRecordRoomsByUserId((int)Clients.Caller.userid);
            }

            //TODO: the default room doesn't have a moduleid associated with it
            //if myRooms is empty, what to do (pass default room)
            if (myRooms == null)
            {
                //load the default room
                var r = rc.GetRoom(DefaultRoomId, moduleId);
                myRooms = new List <Room>();
                myRooms = myRooms.Concat(new[] { r });
            }
            else
            {
                //load the current default room to see if it is in the queue
                var r = rc.GetRoom(DefaultRoomId, moduleId);
                if (!myRooms.Contains(r))
                {
                    myRooms = myRooms.Concat(new[] { r });
                }
            }

            //get all the active rooms and send it back for the Lobby
            var allRooms = rc.GetRooms(moduleId);

            //we are passing in a list of All rooms, and the current user's rooms
            Clients.Caller.PopulateUser(allRooms, myRooms);
            return(base.OnConnected());
        }