コード例 #1
0
 public async Task <IEnumerable <FlightDto> > GetAll()
 {
     try
     {
         return(await _flightRepository.GetAll());
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #2
0
        private static void CreateDefaultFlights(IServiceProvider serviceProvider)
        {
            IFlightsRepository flightsRepository = serviceProvider.GetService <IFlightsRepository>();

            if (flightsRepository.GetAll().Count == 0)
            {
                Random         random            = new Random();
                FlightStatus[] incomingStatuses  = new[] { FlightStatus.Expected, FlightStatus.Delayed, FlightStatus.Landed };
                FlightStatus[] departingStatuses = new[] { FlightStatus.Canceled, FlightStatus.OnTime, FlightStatus.Departed, FlightStatus.Canceled };
                string[]       places            = new[] { "Moscow", "New York", "Sydney", "Los Angeles", "Berlin", "Tokyo", "Paris", "Istanbul", "Rome", "Krakow", "Singapore" };
                for (int i = 0; i < random.Next(5, 10); i++)
                {
                    Flight incomingFlight = new Flight()
                    {
                        TailNumber   = $"{(char)('A' + random.Next(26))}{(char)('A' + random.Next(26))} {(char)('0' + random.Next(9))}{(char)('0' + random.Next(9))}",
                        FlightType   = FlightType.IncomingFlight,
                        Airline      = "International Airline",
                        FlightStatus = incomingStatuses[random.Next(incomingStatuses.Length)],
                        Place        = places[random.Next(places.Length)],
                        Date         = DateTime.Now.AddHours(random.Next(1, 10))
                    };
                    flightsRepository.Save(incomingFlight);
                }
                for (int i = 0; i < random.Next(5, 10); i++)
                {
                    Flight departingFlight = new Flight()
                    {
                        TailNumber   = $"{(char)('A' + random.Next(26))}{(char)('A' + random.Next(26))} {(char)('0' + random.Next(9))}{(char)('0' + random.Next(9))}",
                        FlightType   = FlightType.DepartingFlight,
                        Airline      = "International Airline",
                        FlightStatus = departingStatuses[random.Next(departingStatuses.Length)],
                        Place        = places[random.Next(places.Length)],
                        Date         = DateTime.Now.AddHours(random.Next(1, 10))
                    };
                    flightsRepository.Save(departingFlight);
                }
            }
        }
コード例 #3
0
 public IEnumerable <FlightModel> GetAll()
 {
     return(_flightsRepository.GetAll());
 }