/* Action for clicking the schedule tab on the navigation bar shared between all views */ public async System.Threading.Tasks.Task <IActionResult> ScheduleAsync() { DateTime now = DateTime.Now; try { string email = HttpContext.Session.GetString("username"); Task <IEnumerable <IFlight> > allFlights; if (HttpContext.Session.GetInt32("isAdmin") == 1) { email = ""; allFlights = _db_flights.GetAll(now); } else { allFlights = _db_flights.GetAll(now, "VR-140", email); } ViewBag.dateSelected = now; ViewBag.email = email; ViewBag.Flights = await allFlights; ViewBag.PilotList = await PilotListGenerator.GetPilotEmailsAsync(_db_pilots); ViewBag.RouteList = await RouteListGenerator.GenerateRouteListAsync("VR-140", _db_route); ViewBag.RouteListRaw = await _db_route.GetAll(); ViewBag.RouteSelected = "VR-140"; return(View()); } catch (ArgumentNullException) { /*Dillon & Luke do something here*/ } return(Content("Todo 4")); }
private async System.Threading.Tasks.Task SetViewBagAsync(string email) { var getAllFlights = _db_flights.GetAll(email); ViewBag.dateSelected = DateTime.Now; ViewBag.email = email; ViewBag.Flights = await getAllFlights; ViewBag.PilotList = await PilotListGenerator.GetPilotEmailsAsync(_db_pilot); ViewBag.RouteList = await RouteListGenerator.GenerateRouteListAsync("VR-140", _db_route); }
/*Will Return all flights found between two dates * Times in between flights are all available time slots */ public static async Task <List <DateTime> > getAvailableTimes(FlightRepo _db_flights, DateTime start, DateTime end) { DateTime current = start; List <DateTime> allFlightTimes = new List <DateTime>(); //Get all flights for each day between two time periods while (current.DayOfYear <= end.DayOfYear) { var dayFlights = await _db_flights.GetAll(current); foreach (var flight in dayFlights) { allFlightTimes.Append(flight.TimeOfFlight); } current = current.AddDays(1); } //return allFlightTimes; Could return all unavailable times if better for front end /* * Assuming that flights are schedule rounded to the * quarter hour */ List <DateTime> allAvailableTimes = new List <DateTime>(); current = start; while (current.DayOfYear <= end.DayOfYear) { //When current time passes earliest time, earliest time //is removed from list if (current.TimeOfDay > allFlightTimes[0].TimeOfDay) { allFlightTimes.RemoveRange(0, 1); } //Add current time to available times if it does not //conflict with next earliest time if (current.TimeOfDay != allFlightTimes[0].TimeOfDay) { allAvailableTimes.Add(current); } current = current.AddMinutes(15); } return(allAvailableTimes); }
internal IEnumerable <Flight> GetAll() { return(_repo.GetAll()); }