public ActionResult ShowStops(int routeID)
        {
            List <BL.Stop> stops = BL.Route.GetStopsByRouteID(routeID);

            //we want to abstract the information away from the database schema into the view
            //schema therefore we create "View Models" inside the Models folder and convert the
            //data into those classes
            List <StopView> viewStops = stops.Select(r => new StopView
            {
                StopID = r.StopID,
                lat    = r.Lat,
                lon    = r.Lon,
                Dtimes = r.Dtimes
            }).ToList();


            MajicBusEntities context = new MajicBusEntities();
            List <usp_estimatedBusLineSegment_Result> res = context.usp_estimatedBusLineSegment(DateTime.UtcNow, "-7:00", routeID).ToList();
            List <RouteShape> shapePosition = (from rs in context.RouteShapes
                                               where rs.RouteID == routeID
                                               select rs).ToList();
            List <Classes.Coordinate> busPositions = BL.Bus.GetBusPosition(routeID).Select(bp => new Classes.Coordinate(bp.Latitude, bp.Longitude)).ToList();
            int routeShape = shapePosition.GroupBy(rs => rs.RouteShapeID).OrderByDescending(agg => agg.Count()).First().Key;

            shapePosition = shapePosition.Where(s => s.RouteShapeID == routeShape).OrderBy(rs => rs.SortID).ToList();
            List <BL.Coordinate> busPos = BL.Bus.GetBusPosition(routeID);

            return(View(new BusPositionPage
            {
                RouteShapes = shapePosition.Select(s => new StopView
                {
                    lat = s.Lat,
                    lon = s.Lon
                }).ToList(),
                BusPositions = busPos.Select(bp => new Classes.Coordinate(bp.Latitude, bp.Longitude)).ToList(),
                Stops = viewStops
            }));
        }
Exemple #2
0
        //
        // GET: /Bus/
        public ActionResult GetBusPosition()
        {
            int routeID = 97;
            MajicBusEntities context = new MajicBusEntities();
            List <usp_estimatedBusLineSegment_Result> res = context.usp_estimatedBusLineSegment(DateTime.UtcNow, "-7:00", routeID).ToList();
            List <RouteShape> shapePosition = (from rs in context.RouteShapes
                                               where rs.RouteID == routeID
                                               select rs).ToList();
            int routeShape = shapePosition.GroupBy(rs => rs.RouteShapeID).OrderByDescending(agg => agg.Count()).First().Key;

            shapePosition = shapePosition.Where(s => s.RouteShapeID == routeShape).OrderBy(rs => rs.SortID).ToList();
            List <BL.Coordinate> busPos = BL.Bus.GetBusPosition(routeID);

            return(View(new BusPositionPage
            {
                RouteShapes = shapePosition.Select(s => new StopView
                {
                    lat = s.Lat,
                    lon = s.Lon
                }).ToList(),
                BusPositions = busPos.Select(bp => new Classes.Coordinate(bp.Latitude, bp.Longitude)).ToList()
            }));
        }