Ejemplo n.º 1
0
        public ActionResult <List <RideDTO> > GetRides([FromQuery] int from, [FromQuery] int to, [FromQuery] DateTime date)
        {
            if (date < DateTime.Today)
            {
                return(BadRequest("We cannot travel back in time"));
            }

            var routes = _stopToRouteService.GetRoutes(from, to);
            var rides  = _rideService.GetByIdsList(routes.Select(r => r.Id).ToList());

            var rideDTOs = rides.Where(
                r => (r.StartTime.Date == date.Date && r.StartTime.TimeOfDay > date.TimeOfDay) ||
                (date.Date > r.StartTime.Date && r.IsEveryDayRide)).Select(r =>
            {
                DateTime startTime;
                if (r.IsEveryDayRide)
                {
                    startTime = r.StartTime.Date == DateTime.Today ? r.StartTime : ToRideDate(date, r.StartTime);
                }
                else
                {
                    startTime = r.StartTime;
                }

                return(new RideDTO
                {
                    Id = r.Id,
                    From = from,
                    To = to,
                    StartTime = startTime,
                    TrainStops = _stopToRouteService.GetStops(r.RouteId).Select(s =>
                    {
                        startTime = startTime.AddHours(s.HoursDiff).AddMinutes(s.MinutesDiff);
                        return new RideStopDTO
                        {
                            StopId = s.TrainStop.Id,
                            City = s.TrainStop.City,
                            Name = s.TrainStop.Name,
                            StopNo = s.StopNo,
                            ArrivalTime = startTime
                        };
                    }).ToList(),
                    Train = r.Train,
                    Price = r.Price
                });
            }).ToList();

            return(Ok(rideDTOs));
        }
Ejemplo n.º 2
0
        public ActionResult <List <RoutePatchDTO> > GetAll()
        {
            var routes = _RouteService.GetAll();
            List <RoutePatchDTO> list = routes.Select(x => new RoutePatchDTO
            {
                Id    = x.Id,
                Name  = x.Name,
                Stops = _StopToRouteService.GetStops(x.Id).Select(stop => new RouteStopDTO
                {
                    StopId      = stop.TrainStopId,
                    StopNo      = stop.StopNo,
                    HoursDiff   = stop.HoursDiff,
                    MinutesDiff = stop.MinutesDiff
                }).ToList()
            }).ToList();

            return(Ok(list));
        }