public BusRouteRepository(BusManagerDbContext dbContext) { _dbContext = dbContext; RoutsSchedule = new List <BusRoute> [_dbContext.BusStops.Count]; CalculatedRoutsCached = new Dictionary <string, List <BusRoute> >(); //If the solution reqired is the fastest on execution for an improved user experience, //this will help to transform each request in to a O(1) after the set up is done. // So we set up the schedules in a dictionary based on 15 minute chunks. //so when the users request the information, everything will be calcualted faster and from memory. //depending of the scalability expected this solution may not work var stopIndex = 0; foreach (var stop in _dbContext.BusStops) { var nextStops = new List <BusRoute>(); var routeIndex = 0; foreach (var route in _dbContext.BusRoutes) { if (RoutsSchedule[stopIndex] == null) { RoutsSchedule[stopIndex] = new List <BusRoute>(); } RoutsSchedule[stopIndex].Add(route); routeIndex++; } stopIndex++; } }
public BusStopRepository(BusManagerDbContext dbContext) { _dbContext = dbContext; }