public List <TimeTableViewModelRow> GetTimeTable(List <Port> ports) { var timetables = _timeTables.All(); var allEntries = timetables.SelectMany(x => x.Entries).OrderBy(x => x.Time).ToList(); var rows = new List <TimeTableViewModelRow>(); foreach (var timetable in allEntries) { var origin = ports.Single(x => x.Id == timetable.OriginId); var destination = ports.Single(x => x.Id == timetable.DestinationId); var destinationName = destination.Name; var originName = origin.Name; var ferry = _ferryService.NextFerryAvailableFrom(origin.Id, timetable.Time); var arrivalTime = timetable.Time.Add(timetable.JourneyTime); var row = new TimeTableViewModelRow { DestinationPort = destinationName, FerryName = ferry == null ? "" : ferry.Name, JourneyLength = timetable.JourneyTime.ToString("hh':'mm"), OriginPort = originName, StartTime = timetable.Time.ToString("hh':'mm"), ArrivalTime = arrivalTime.ToString("hh':'mm"), }; rows.Add(row); } return(rows); }
public List<TimeTableViewModelRow> GetTimeTable(List<Port> ports) { var timetables = _timeTables.All(); var allEntries = timetables.SelectMany(x => x.Entries).OrderBy(x => x.Time).ToList(); var rows = new List<TimeTableViewModelRow>(); foreach (var timetable in allEntries) { var origin = ports.Single(x => x.Id == timetable.OriginId); var destination = ports.Single(x => x.Id == timetable.DestinationId); var destinationName = destination.Name; var originName = origin.Name; var ferry = _ferryService.NextFerryAvailableFrom(origin.Id, timetable.Time); var arrivalTime = timetable.Time.Add(timetable.JourneyTime); var row = new TimeTableViewModelRow { DestinationPort = destinationName, FerryName = ferry == null ? "" : ferry.Name, JourneyLength = timetable.JourneyTime.ToString("hh':'mm"), OriginPort = originName, StartTime = timetable.Time.ToString("hh':'mm"), ArrivalTime = arrivalTime.ToString("hh':'mm"), }; rows.Add(row); } return rows; }