Example #1
0
        public IEnumerable <AvailableCrossing> GetAvailableCrossings(TimeSpan time, int fromPort, int toPort)
        {
            var ports      = new Ports().All();
            var timetables = _timeTables.All();

            var allEntries = timetables.SelectMany(x => x.Entries).OrderBy(x => x.Time).ToList();

            foreach (var timetable in allEntries)
            {
                var origin      = ports.Single(x => x.Id == timetable.OriginId);
                var destination = ports.Single(x => x.Id == timetable.DestinationId);
                var ferry       = _ferryService.NextFerryAvailableFrom(timetable.OriginId, timetable.Time);

                if (toPort == destination.Id && fromPort == origin.Id)
                {
                    if (timetable.Time >= time)
                    {
                        var bookings  = _bookings.All().Where(x => x.JourneyId == timetable.Id);
                        var seatsLeft = ferry.Passengers - bookings.Sum(x => x.Passengers);
                        if (seatsLeft > 0)
                        {
                            yield return(new AvailableCrossing
                            {
                                Arrive = timetable.Time.Add(timetable.JourneyTime),
                                FerryName = ferry.Name,
                                SeatsLeft = ferry.Passengers - bookings.Sum(x => x.Passengers),
                                SetOff = timetable.Time,
                                OriginPort = origin.Name,
                                DestinationPort = destination.Name,
                                JourneyId = timetable.Id
                            });
                        }
                    }
                }
            }
        }
Example #2
0
 public FerryAvailabilityService(TimeTables timeTables, Ports ports, Ferries ferries)
 {
     _timeTables = timeTables;
     _ports      = ports;
     _ferries    = ferries;
 }
Example #3
0
 public PortManager(Ports ports, Ferries ferries)
 {
     _ports   = ports;
     _ferries = ferries;
 }