Ejemplo n.º 1
0
        // Display Time Table Command - Displays the time table
        private static void DisplayTimeTableCommand()
        {
            try
            {
                Console.WriteLine("Ferry Time Table:");
                Console.WriteLine("-----------------");

                foreach (var port in ManagementSystem.GetAllPorts())
                {
                    PrintPortHeader(port.Name);

                    // Every Journey is based on an entry in the timetable, use them to display timetable
                    foreach (var journey in ManagementSystem.GetAllJourneys().OrderBy(x => x.Origin.Name).ThenBy(x => x.Departure))
                    {
                        if (journey.Origin.Id == port.Id)
                        {
                            Console.WriteLine("| {0} | {1} | {2} | {3} | {4} |",
                                              journey.Departure.ToString().PadRight(8),
                                              journey.Destination.Name.PadRight(13),
                                              journey.Travel.ToString().PadRight(13),
                                              journey.Ferry.Name.PadRight(18),
                                              journey.Arrival.ToString().PadRight(8)
                                              );
                        }
                    }
                }
            }
            catch (Exception)
            {
                DisplayTimeTableError();
            }
        }
Ejemplo n.º 2
0
 // Determines if a user can book a particular journey based off of what they need (# passengers, # tickets, weight)
 private bool CanBook(int journeyId, int passengers, int vehicles, int weight)
 {
     foreach (var journey in ManagementSystem.GetAllJourneys())
     {
         if (journey.Id == journeyId)
         {
             var bookings     = _bookings.Where(x => x.Journey.Id == journeyId);
             var seatsLeft    = journey.Ferry.Passengers - bookings.Sum(x => x.Passengers);
             var vehiclesLeft = journey.Ferry.Vehicles - bookings.Sum(x => x.Vehicles);
             var weightLeft   = journey.Ferry.Weight - bookings.Sum(x => x.Weight);
             return(seatsLeft >= passengers && vehiclesLeft >= vehicles && weightLeft >= weight);
         }
     }
     return(false);
 }