public List <DepartureTimeVm> GetDepartureTimes(TravelSearchVm travelSearch) { var departureTimeList = new List <DepartureTimeVm>(); var DepartureTimeStopList = new List <DepartureTimeStop>(); var DepartureTimestop = new DepartureTimeStop() { Name = "Egersund", DepartureTime = new TimeSpan(12, 20, 0) }; DepartureTimeStopList.Add(DepartureTimestop); DepartureTimeStopList.Add(DepartureTimestop); DepartureTimeStopList.Add(DepartureTimestop); var departureTime = new DepartureTimeVm() { TripId = 1, DepartureStationId = 1, DepartureStation = "Sandnes", DepartureStationTime = new TimeSpan(8, 47, 0), ArrivalStationId = 3, ArrivalStation = "Audnedal", ArrivalStationTime = new TimeSpan(16, 25, 0), Stops = DepartureTimeStopList }; return(departureTimeList); }
public ActionResult DepartureTimes(TravelSearchVm travelSearch) //Inneholder avgangsstasjon ID, ankomststasjon ID og dato for valgt tur/trip { if (travelSearch != null) { ViewBag.TicketDate = travelSearch.Date; } var tripService = new TripService(); var departureTimeList = tripService.GetDepartureTimes(travelSearch); return(View(departureTimeList)); }
public List <DepartureTimeVm> GetDepartureTimes(TravelSearchVm travelSearch) { var tripRepository = _repository; var departureTimes = tripRepository.GetDepartureTimes(travelSearch); foreach (var departureTime in departureTimes) { var price = tripRepository.GetPrice(departureTime.TripId); var numberOfStops = departureTime.Stops.Count; var totalPrice = CalculatePrice(price.BasePrice, price.StopsPrice, numberOfStops); departureTime.Price = totalPrice; } return(departureTimes); }
public ActionResult Index(TravelSearchVm travelSearch) { return(RedirectToAction("DepartureTimes", travelSearch)); }
public List <DepartureTimeVm> GetDepartureTimes(TravelSearchVm travelSearch) { using (Oblig1Context db = new Oblig1Context()) { var ois = db.OperationalIntervals .Where(a => a.StartDate <= travelSearch.Date && a.EndDate >= travelSearch.Date); switch (travelSearch.Date.DayOfWeek) { case DayOfWeek.Sunday: ois = ois.Where(a => a.Sunday); break; case DayOfWeek.Monday: ois = ois.Where(a => a.Monday); break; case DayOfWeek.Tuesday: ois = ois.Where(a => a.Tuesday); break; case DayOfWeek.Wednesday: ois = ois.Where(a => a.Wednesday); break; case DayOfWeek.Thursday: ois = ois.Where(a => a.Thursday); break; case DayOfWeek.Friday: ois = ois.Where(a => a.Friday); break; case DayOfWeek.Saturday: ois = ois.Where(a => a.Saturday); break; } var trips = ois.SelectMany(a => a.Trips) .Where(a => a.Schedules.Any(b => b.StationId == travelSearch.DepartureId) && a.Schedules.Any(b => b.StationId == travelSearch.ArrivalId)) .ToList(); var departureTimeList = new List <DepartureTimeVm>(); foreach (var trip in trips) { var arrivalSchedule = trip.Schedules.SingleOrDefault(a => a.StationId == travelSearch.ArrivalId); var departureSchedule = trip.Schedules.SingleOrDefault(a => a.StationId == travelSearch.DepartureId); if (departureSchedule.DepartureTime < arrivalSchedule.ArrivalTime) { var stops = trip.Schedules .Where(a => a.DepartureTime > departureSchedule.DepartureTime && a.ArrivalTime < arrivalSchedule.ArrivalTime) .OrderBy(a => a.DepartureTime) .Select(a => new DepartureTimeStop { Name = a.Station.StationName, DepartureTime = a.DepartureTime.Value }).ToList(); departureTimeList.Add(new DepartureTimeVm { TripId = trip.Id, DepartureStationId = travelSearch.DepartureId, DepartureStation = departureSchedule.Station.StationName, DepartureStationTime = departureSchedule.DepartureTime.Value, ArrivalStationId = travelSearch.ArrivalId, ArrivalStation = arrivalSchedule.Station.StationName, ArrivalStationTime = arrivalSchedule.ArrivalTime.Value, Stops = stops }); } } return(departureTimeList); } }