// GET: Customers
        public async Task <IActionResult> Index(string flightNumber, string searchFlight)
        {
            DataInfo info              = new DataInfo();
            var      userId            = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var      customerToDisplay = _repo.Customer.GetCustomer(userId);

            if (customerToDisplay == null)
            {
                return(RedirectToAction("Create"));
            }
            FlightInfo flight = new FlightInfo();
            CustomerFlightInfoViewModel customerFlight = new CustomerFlightInfoViewModel();

            if (flightNumber != null)
            {
                flightNumber = RemoveSpaces(flightNumber);
                info         = await _flightService.GetArrivalInfo(flightNumber);

                if (info.data.Length != 0)
                {
                    flight.CustomerId   = customerToDisplay.Id;
                    flight.FlightNumber = flightNumber;
                    _repo.Flight.CreateFlight(flight);
                    await _context.SaveChangesAsync();
                }
            }
            var flights = _repo.Flight.GetFlights(customerToDisplay.Id);

            ViewBag.FlightNum = flightNumber;
            ViewBag.Check     = flight.FlightNumber;
            if (flights.Count != 0)
            {
                if (flights[flights.Count - 1].Airport == null || searchFlight != null)
                {
                    info = await _flightService.GetArrivalInfo(flights[flights.Count - 1].FlightNumber);
                }
            }

            ViewBag.Flights         = info.data;
            customerFlight.Customer = customerToDisplay;
            customerFlight.Flights  = flights;
            if (searchFlight != null)
            {
                return(await SetFlightInfo(info, customerToDisplay, flights[flights.Count - 1], Convert.ToInt32(searchFlight)));
            }
            return(View(customerFlight));
        }
        public async Task <IActionResult> FlightInfo(TimeSpan?time, int flightId)
        {
            CustomerFlightInfoViewModel customerFlight = new CustomerFlightInfoViewModel();
            var userId   = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var customer = _repo.Customer.GetCustomer(userId);

            if (flightId != 0)
            {
                customer.flightId = flightId;
            }
            var flight = _repo.Flight.GetFlight(customer.flightId);

            if (time != null)
            {
                flight.SelectedArrivalTime = time;
            }
            _repo.Customer.EditCustomer(customer);
            _repo.Flight.EditFlight(flight);
            await _context.SaveChangesAsync();

            customerFlight.Customer   = customer;
            customerFlight.FlightInfo = flight;
            Airport airport = await _tsaWaitTimesService.GetWaitTimes(flight.AirportCode);

            string firstTimeSlot = airport.estimated_hourly_times[0].timeslot;
            char   firstChar     = firstTimeSlot[0];
            int    firstTime     = Convert.ToInt32(Char.GetNumericValue(firstChar));
            double?transitMins;
            bool   withinTime;

            if (flight.SelectedArrivalTime.HasValue || time.HasValue)
            {
                if (flight.SelectedArrivalTime.Value.Hours < firstTime || flight.SelectedArrivalTime.Value.Hours > airport.estimated_hourly_times.Length)
                {
                    withinTime        = true;
                    ViewBag.TimeCheck = withinTime;
                    return(View(customerFlight));
                }
                for (int i = firstTime; i < airport.estimated_hourly_times.Length; i++)
                {
                    TimeSpan start = new TimeSpan(i, 0, 0);
                    TimeSpan end   = new TimeSpan((i + 1), 0, 0);
                    if ((flight.SelectedArrivalTime >= start) && (flight.SelectedArrivalTime <= end))
                    {
                        flight.TSAWaitTimeOnArrival = airport.estimated_hourly_times[i].waittime;
                        break;
                    }
                }
                _repo.Flight.EditFlight(flight);
                await _context.SaveChangesAsync();

                EpochTimeConverter(flight);
                TravelInfo travelInfo = await _directions.GetDirections(customer, flight);

                SetDirectionsInfo(travelInfo, customer);
                transitMins         = customer.duration + flight.TSAWaitTimeOnArrival;
                ViewBag.TransitTime = transitMins;
                DateTime leaveTime = ConvertTime(transitMins, flight);
                ViewBag.LeaveTimeData = leaveTime;
                string dateToDisplay = leaveTime.ToShortDateString();
                string timeToDisplay = leaveTime.ToString("hh:mm:ss tt");
                ViewBag.LeaveTime = $"{dateToDisplay} {timeToDisplay}";
            }
            return(View(customerFlight));
        }