Exemple #1
0
        // dequeques a user from a bus
        public void DequeueUserFromBus(string userName, string busName, string terminalBusStop)
        {
            for (int i = 0; i < _busList.FindBusWithBusName(busName).GetPassengerList().Count(); i++)
            {
                if (_busList.FindBusWithBusName(busName).GetPassengerList()[i].GetMobileNum() == _userList.FindUserWithName(userName).GetMobileNum())
                {
                    _busList.FindBusWithBusName(busName).GetPassengerList().RemoveAt(i);

                    // update user location and user status
                    User tempUser = _userList.FindUserWithName(userName);
                    Journey lastJourney = new Journey(tempUser.GetJourneyPlan().GetInitialStop(), terminalBusStop, busName, _userList.FindUserWithName(userName).GetJourneyPlan().GetDepartTime(), _time);

                    tempUser.AddJourney(lastJourney);
                    tempUser.UpdateUserStatus(USER_STATUS.inactive);
                    tempUser.UpdateUserLocation(null);
                    
                    //_userList.FindUserWithName(userName).AddJourney(lastJourney);
                    User user = _userList.FindUserWithName(userName);

                    if (!_busList.FindBusWithBusName(busName).ExistSubscriber(user.GetMobileNum()))
                    {
                        if (user.NumberOfTimesTravelThisBus(busName) >= BUS_THRESHOLD)
                            AddBusServiceSubscriber(user.GetMobileNum(), busName);
                    }

                    List<Route> busroute = _busList.FindBusWithBusName(busName).GetRouteList();

                    for (int j = 0; j < busroute.Count; j++)
                    {
                        if (busroute.ElementAt(j).GetBusStopName() == lastJourney.GetInitialStop())
                        {
                            if (!_busStopList.FindBusStopWithBusStopName(busroute.ElementAt(j).GetBusStopName()).ExistSubscriber(user.GetMobileNum()))
                                if (NumberOfTimesUserGoThroughThisBusStop(user.GetMobileNum(), busroute.ElementAt(j).GetBusStopName()) >= BUSSTOP_THRESHOLD)
                                    AddBusStopSubscriber(user.GetMobileNum(), busroute.ElementAt(j).GetBusStopName());
                        }
                    }

                    break;
                }
            }
        }