Ejemplo n.º 1
0
        // helper function to get amount of available seats from a booked bus
        public int GetAvailableSeatCountFromBookedBus(DateTime dateTime, string direction, string busId, int neededAmountOfSeats)
        {
            int requiredSeats = neededAmountOfSeats;

            ShuttleBus bus = _shuttleBusDAO.RetrieveShuttleBusById(busId);

            //find a proper way to get all passengers of a bus
            //currently this only gives you passengers of that schedule
            List <ShuttlePassenger> passengerList = GetShuttlePassengersOfBus(busId, dateTime, direction);

            if (passengerList.Count == bus.RetrieveShuttleBusCapacity())
            {
                //this bus is full. go to next available bus.
                Debug.WriteLine("[GetAvailableSeatCountFromBookedBus - CHECK] - Bus of Id " + bus.RetrieveId() + " already fully booked.");
                return(0);
            }

            //(current number of passengers) + (to-be-added passengers) is less or equal to (max capacity)
            if (passengerList.Count + requiredSeats <= bus.RetrieveShuttleBusCapacity())
            {
                //possible to book all remaining needed seats under this bus.
                Debug.WriteLine("[GetAvailableSeatCountFromBookedBus - CHECK/pass] - GOOD CAPACITY - Able to book " + requiredSeats + " amount of seats for bus " + bus.RetrieveId());

                return(requiredSeats);
            }

            else
            {
                //current bus can take 'some' passengers, but not all.

                //get number of seats that we can put in 'right now'

                int possibleSeatsCount = bus.RetrieveShuttleBusCapacity() - passengerList.Count;

                Debug.WriteLine("[GetAvailableSeatCountFromBookedBus - CHECK] - OVER CAPACITY - " +
                                "Unable to book " + requiredSeats + " amount of seats for bus " + bus.RetrieveId());
                Debug.WriteLine("[GetAvailableSeatCountFromBookedBus - CHECK] - OVER CAPACITY - " +
                                "Bus " + bus.RetrieveId() + " currently can offer " +
                                (bus.RetrieveShuttleBusCapacity() - passengerList.Count) + " seats.");

                requiredSeats -= possibleSeatsCount;  //update remaining amt of seats to add

                Debug.WriteLine("[GetAvailableSeatCountFromBookedBus - CHECK] - " + requiredSeats + " more seats needed.");

                return(bus.RetrieveShuttleBusCapacity() - passengerList.Count);
            }
        }
Ejemplo n.º 2
0
        public string ReturnIndexOfLastItem()
        {
            ShuttleBus finalObject = _context.ShuttleBus.AsEnumerable().OrderByDescending(x => x.RetrieveId()).FirstOrDefault();

            return(finalObject.RetrieveId());
        }