示例#1
0
 public static void SaveRoute(string path, Route route)
 {
     route.PrepareForSaving();
     using (var context = RouteDbContext.GetContext(path))
     {
         context.Route.Add(route);
         context.SaveChanges();
     }
 }
        public DatabaseTestBase()
        {
            _connection = new SqliteConnection("DataSource=:memory:");
            _connection.Open();

            _options = new DbContextOptionsBuilder <RouteDbContext>()
                       .UseSqlite(_connection)
                       .Options;

            using (var context = new RouteDbContext(_options))
            {
                context.Database.EnsureCreated();
            }
        }
示例#3
0
        public static async Task <Route> GetRouteAsync(string path)
        {
            using (var context = RouteDbContext.GetContext(path))
            {
                var route = await context.Route
                            .Include(r => r.Sections).ThenInclude(s => s.Polygon)
                            .Include(r => r.Waypoints)
                            .ThenInclude(poi => (poi as PointOfInterest).Translations)
                            .FirstOrDefaultAsync()
                            ??
                            new Route()
                {
                    Waypoints = new List <RoutePoint>(),
                    Sections  = new List <Section>()
                };
                route.RecoverFromLoading();

                return(route);
            }
        }
示例#4
0
 public RoutePageController(ILogger <RoutePageController> logger, RouteDbContext dbcontext)
 {
     _logger = logger;
     _db     = dbcontext;
 }
示例#5
0
 public CompanyReponsitory(RouteDbContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
示例#6
0
        // Map a RouteDBContext object to Route object.
        public Route MapRouteDBToRoute(RouteDbContext RouteDB)
        {
            using (var db = new DB())
            {
                List <Station> RouteStations = new List <Station>();

                foreach (var s in RouteDB.RouteStations)
                {
                    List <TrainSchedule> TrainSchedules = new List <TrainSchedule>();

                    foreach (var ts in s.TrainSchedules)
                    {
                        var OneStation = new Station
                        {
                            StationID   = ts.StationID,
                            StationName = ts.Station.StationName,
                        };

                        var OneTrain = new Train
                        {
                            TrainID = ts.TrainID,
                        };

                        var OneTrainSchedule = new TrainSchedule
                        {
                            StationID        = ts.StationID,
                            TrainID          = ts.TrainID,
                            Station          = OneStation,
                            Train            = OneTrain,
                            TrainArrivalTime = ts.TrainArrivalTime
                        };

                        TrainSchedules.Add(OneTrainSchedule);
                    }


                    var OtherStation = new Station
                    {
                        StationName    = s.StationName,
                        TrainSchedules = TrainSchedules
                    };



                    RouteStations.Add(OtherStation);
                }

                List <Train> RouteTrains = new List <Train>();


                foreach (var t in RouteDB.RouteTrains)
                {
                    var OneTrain = new Train
                    {
                        TrainID = t.TrainID
                    };
                    RouteTrains.Add(OneTrain);
                }


                var OneRoute = new Route
                {
                    RouteID       = RouteDB.RouteID,
                    RouteLength   = RouteDB.RouteLength,
                    RouteStations = RouteStations,
                    RouteTrains   = RouteTrains
                };


                return(OneRoute);
            }
        }
示例#7
0
 public HomeController()
 {
     _context = new RouteDbContext();
 }