Exemplo n.º 1
0
        public async Task <IActionResult> ViewAllFlights()
        {
            //get all flights and get list of location
            var flights = await _globalRepo.GetAll <Flight>(Flight.tableName);

            var locations = (await _countryRepo.GetAllLocById2(flights.Select(s => s.OriginLocID).Concat(flights.Select(s => s.DestLocID)).Distinct())).OrderBy(o => o.ID);

            //iterate through origin flights ordered by loc id and assign location details
            int i = 0;

            foreach (var f in flights.OrderBy(o => o.OriginLocID))
            {
                while (f.OriginLocID != locations.ElementAt(i).ID)   //iterate to the next location details if not matched
                {
                    i++;
                }
                f.OriginLoc1 = locations.ElementAt(i);
            }

            //iterate through return flights ordered by loc id and assign location details
            i = 0;
            foreach (var f in flights.OrderBy(o => o.DestLocID))
            {
                while (f.DestLocID != locations.ElementAt(i).ID) //iterate to the next location details if not matched
                {
                    i++;
                }
                f.DestLoc1 = locations.ElementAt(i);
            }
            return(View(flights));
        }