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(); } }
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); } }
public RoutePageController(ILogger <RoutePageController> logger, RouteDbContext dbcontext) { _logger = logger; _db = dbcontext; }
public CompanyReponsitory(RouteDbContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); }
// 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); } }
public HomeController() { _context = new RouteDbContext(); }