コード例 #1
0
        public static List <StopDataModel> StopTimesForStopLoggedIn(this MojBusContext context, string stopName, int directionId, string userId, DateTime date)
        {
            object[] sqlParams =
            {
                new SqlParameter("@StopName",    stopName),
                new SqlParameter("@DirectionId", directionId),
                new SqlParameter("@Date",        date)
            };

            List <FavouriteStopRoutes> favouriteStopRoutes = context
                                                             .FavouriteStopRoutes
                                                             .Where(x => x.UserId == userId &&
                                                                    x.StopName == stopName &&
                                                                    x.DirectionId == directionId)
                                                             .ToList();
            List <StopDataEntity> data = context
                                         .Set <StopDataEntity>()
                                         .FromSql("exec dbo.TripsWithTimesForStationAndTripDirection @StopName, @DirectionId, @Date;", sqlParams)
                                         .ToList();

            return(data
                   .StopDataEntityToModel(stopName)
                   .GroupByTripShortName()
                   .OrderBy(x => x.TripShortName)
                   .ToList()
                   .AddFavouritesToStops(favouriteStopRoutes));
        }
コード例 #2
0
        public static bool AddStopRouteToFavourites(this MojBusContext context, FavouriteStopRouteModel favouriteStop)
        {
            bool isAdded = false;
            var  result  = context.FavouriteStopRoutes.Where(x => x.UserId == favouriteStop.UserId &&
                                                             x.DirectionId == favouriteStop.DirectionId &&
                                                             x.StopName == favouriteStop.StopName &&
                                                             x.RouteShortName == favouriteStop.RouteShortName).ToList();

            if (result.Count != 0)
            {
                context.FavouriteStopRoutes.RemoveRange(result);
                isAdded = false;
            }
            else
            {
                context.FavouriteStopRoutes.Add(new FavouriteStopRoutes()
                {
                    UserId         = favouriteStop.UserId,
                    RouteShortName = favouriteStop.RouteShortName,
                    StopName       = favouriteStop.StopName,
                    DirectionId    = favouriteStop.DirectionId
                });
                isAdded = true;
            }
            context.SaveChanges();

            return(isAdded);
        }
コード例 #3
0
        public static List <StopDataModel> StopTimesForStop(this MojBusContext context, string stopName, DateTime date)
        {
            object[] sqlParams =
            {
                new SqlParameter("@StopName", stopName),
                new SqlParameter("@Date",     date)
            };

            List <StopDataEntity> data = context.Set <StopDataEntity>().FromSql("exec dbo.TripsWithTimesForStation @StopName, @Date;", sqlParams).ToList();

            return(data.StopDataEntityToModel(stopName));
        }
コード例 #4
0
        public static StopLocationModel StopLocation(this MojBusContext context, string stopName, int directionId)
        {
            StopLocationModel model = new StopLocationModel();
            var data = context.Gtfsstops.Where(x => x.StopName == stopName && x.StopDirectionId == directionId).FirstOrDefault();

            if (data != null)
            {
                model = new StopLocationModel()
                {
                    StopLat = data.StopLat, StopLon = data.StopLon
                }
            }
            ;
            return(model);
        }
コード例 #5
0
        public static List <StopTimes> RouteStopTimes(this MojBusContext context, string routeShortName, DateTime date)
        {
            object[] sqlParams =
            {
                new SqlParameter("@RouteShortName", routeShortName),
                new SqlParameter("@Date",           date)
            };

            List <RouteStopsEntity> data = context
                                           .Set <RouteStopsEntity>()
                                           .FromSql("exec dbo.RouteStopTimes @RouteShortName, @Date;", sqlParams)
                                           .ToList();

            return(data
                   .RouteStopsEntityToStopTimesModel());
        }
コード例 #6
0
        public static List <StopLocationModel> LocationsForRouteStops(this MojBusContext context, string routeShortName, int directionId, DateTime date)
        {
            object[] sqlParams =
            {
                new SqlParameter("@RouteShortName", routeShortName),
                new SqlParameter("@DirectionId",    directionId),
                new SqlParameter("@Date",           date)
            };

            List <RouteStopsEntity> data = context
                                           .Set <RouteStopsEntity>()
                                           .FromSql("exec dbo.RouteStopTimesForDirectionId @RouteShortName, @DirectionId, @Date;", sqlParams)
                                           .ToList();

            return(data
                   .ConvertToRouteStopsDistinctedByStops());
        }
コード例 #7
0
        public static List <StopDataModel> StopTimesForStop(this MojBusContext context, string stopName, string routeShortName, int directionId, DateTime date)
        {
            object[] sqlParams =
            {
                new SqlParameter("@StopName",       stopName),
                new SqlParameter("@RouteShortName", routeShortName),
                new SqlParameter("@DirectionId",    directionId),
                new SqlParameter("@Date",           date)
            };

            List <StopDataEntity> data = context
                                         .Set <StopDataEntity>()
                                         .FromSql("exec dbo.TripsWithTimesForStationAndRouteDirection @StopName, @RouteShortName, @DirectionId, @Date;", sqlParams)
                                         .AsNoTracking()
                                         .ToList();

            return(data.StopDataEntityToModel(stopName));
        }
コード例 #8
0
        public static TripPlannerModel DepartureTimetableBetweenTwoStops(this MojBusContext context, string stopNameFrom, string stopNameTo, DateTime date)
        {
            object[] sqlParams =
            {
                new SqlParameter("@StopNameFrom", stopNameFrom),
                new SqlParameter("@StopNameTo",   stopNameTo),
                new SqlParameter("@Date",         date)
            };

            List <TripPlannerEntity> data = context
                                            .Set <TripPlannerEntity>()
                                            .FromSql("exec dbo.DepartureTimetableBetweenTwoStations @StopNameFrom, @StopNameTo, @Date;", sqlParams)
                                            .AsNoTracking()
                                            .ToList();

            return(data
                   .ConvertToTripPlannerModel());
        }
コード例 #9
0
        public static List <StopDataModel> GetFavouriteStopsLoggedIn(this MojBusContext context, string userId)
        {
            List <FavouriteStopRoutes> favouriteStopRoutes = context
                                                             .FavouriteStopRoutes
                                                             .Where(x => x.UserId == userId)
                                                             .ToList();
            List <StopDataModel> stops = new List <StopDataModel>();
            DateTime             date  = DateTime.Now;

            if (favouriteStopRoutes.Count() == 0)
            {
                return(stops);
            }

            foreach (FavouriteStopRoutes route in favouriteStopRoutes)
            {
                stops.AddRange(context.StopTimesForStop(route.StopName, route.RouteShortName, route.DirectionId, date)
                               .GroupByTripShortName()
                               .ToList());
            }
            stops.ForEach(x => { x.isFavourite = true; });

            return(stops);
        }
コード例 #10
0
 public MojBusApiController(MojBusContext context)
 {
     _context = context;
 }
コード例 #11
0
 public FavouriteStopsViewComponent(MojBusContext context, UserManager <ApplicationUser> userManager)
 {
     _context     = context;
     _userManager = userManager;
 }
コード例 #12
0
 public StopsController(MojBusContext context, UserManager <ApplicationUser> userManager)
 {
     _context     = context;
     _userManager = userManager;
 }
コード例 #13
0
 public HomeController(MojBusContext context)
 {
     _context = context;
 }
コード例 #14
0
 //old api methods
 public static IQueryable <Gtfsroutes> GetRoutes(this MojBusContext context)
 {
     return(context.Gtfsroutes.OrderBy(x => x.RouteShortName));
 }
コード例 #15
0
 public static IQueryable <Gtfsstops> GetStops(this MojBusContext context)
 {
     return(context.Gtfsstops.OrderBy(x => x.StopName).ThenBy(x => x.StopDirectionId));
 }