// Deleting a server with the ID "id" from context
        public static async Task <int> DeleteServer(FlightPlanDBContext _context, string id)
        {
            Server server = _context.Servers.Where(item => item.ServerId == id).First();

            _context.Servers.Remove(server);
            return(await _context.SaveChangesAsync());
        }
 // Get all flights that are active acoording to the time of reletive_to from the context
 public static IEnumerable <Flight> GetFlights(FlightPlanDBContext _context, DateTime relative_to)
 {
     return(_context.Flight.Include(item => item.FlightPlan).Include(item => item.FlightPlan.InitialLocation)
            .Include(item => item.FlightPlan.Segments).ToList()
            .Where(filter => filter.FlightPlan.InitialLocation.DateTime.ToLocalTime()
                   <= relative_to && relative_to <= filter.FlightPlan.EndDateFlight.ToLocalTime()));
 }
        // Remove a flight with the same ID as "id" from the ontext given
        public static async Task <int> RemoveFlight(FlightPlanDBContext _context, string id)
        {
            // Finding the flight
            Flight flight = _context.Flight.Include(item => item.FlightPlan)
                            .Where(item => item.FlightIdentifier == id).First();
            FlightPlan flightPlan = flight.FlightPlan;

            // Removing the associated flight plan
            _context.FlightPlans.Remove(flightPlan);
            _context.Flight.Remove(flight);
            return(await _context.SaveChangesAsync());
        }
 // Return the last used ID in the context
 public static string FindLastID(FlightPlanDBContext db)
 {
     return(!db.FlightPlans.Include(item => item.Flight).OrderByDescending(item => item.Flight.FlightIdentifier).Any()
         ? "AAAA-0000" : db.FlightPlans.Include(item => item.Flight).OrderByDescending(item => item.Flight.FlightIdentifier).First()
            .Flight.FlightIdentifier);
 }
 // Adding a server to the given context
 public static async Task <int> AddServer(FlightPlanDBContext _context, Server server)
 {
     _context.Add(server);
     return(await _context.SaveChangesAsync());
 }
 // Get all servers from the context asynchronously
 public static async Task <List <Server> > GetListOfServers(FlightPlanDBContext _context)
 {
     return(await _context.Servers.ToListAsync());
 }
 // Get all servers from the context
 public static List <Server> GetServers(FlightPlanDBContext _context)
 {
     return(_context.Servers.ToList());
 }
 // Send flightPlan and flight to the context given
 public static async Task <int> AddAFlightPlanAndAFlight(FlightPlanDBContext _context, FlightPlan flightPlan, Flight flight)
 {
     _context.Add(flightPlan);
     _context.Add(flight);
     return(await _context.SaveChangesAsync());
 }
 // Find the last id in the context given
 public static IQueryable <FlightPlan> FindFlightPlanId(FlightPlanDBContext _context, string id)
 {
     return(_context.FlightPlans.Include(item => item.Flight).Include(item => item.InitialLocation)
            .Include(item => item.Segments).Where(item => id == null || item.Flight.FlightIdentifier == id).Take(1));
 }