コード例 #1
0
        // 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());
        }
コード例 #2
0
 // 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()));
 }
コード例 #3
0
        // 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());
        }
コード例 #4
0
 // 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);
 }
コード例 #5
0
 // Adding a server to the given context
 public static async Task <int> AddServer(FlightPlanDBContext _context, Server server)
 {
     _context.Add(server);
     return(await _context.SaveChangesAsync());
 }
コード例 #6
0
 // Get all servers from the context asynchronously
 public static async Task <List <Server> > GetListOfServers(FlightPlanDBContext _context)
 {
     return(await _context.Servers.ToListAsync());
 }
コード例 #7
0
 // Get all servers from the context
 public static List <Server> GetServers(FlightPlanDBContext _context)
 {
     return(_context.Servers.ToList());
 }
コード例 #8
0
 // 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());
 }
コード例 #9
0
 // 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));
 }