public void Flight_D1908_20170408_Partial() { FlightContext fc = new FlightContext("6770"); int callbacks = 0; fc.OnRadarContact += (sender, args) => { Assert.AreEqual(null, ((FlightContext)sender).Flight.DepartureTime); Assert.AreEqual(false, ((FlightContext)sender).Flight.DepartureInfoFound); Assert.AreEqual(0, ((FlightContext)sender).Flight.DepartureHeading); callbacks++; }; fc.OnLanding += (sender, args) => { Assert.AreEqual(636272628474023926, ((FlightContext)sender).Flight.ArrivalTime?.Ticks); Assert.AreEqual(250, ((FlightContext)sender).Flight.ArrivalHeading); callbacks++; }; // These events should NOT be fired fc.OnTakeoff += (sender, args) => Assert.Fail(); fc.OnCompletedWithErrors += (sender, e) => Assert.Fail(); fc.Process(Common.ReadFlightPoints("2017-04-08_D-1908.csv").Skip(500)); Assert.AreEqual(2, callbacks); }
public static bool IsValid(string email, bool isExistingPilot) { var cleanEmail = ParseEmail(email); var valid = false; try { var addr = new System.Net.Mail.MailAddress(cleanEmail); if (addr.Address == cleanEmail) { valid = true; } } catch { return(false); } if (valid) { if (!isExistingPilot) { return(true); } else { using (var shortDb = new FlightContext()) { return(shortDb.Pilots.Any(d => d.Email == cleanEmail)); } } } return(false); }
public IEnumerable <Flight> QueryFlights(Expression <Func <Flight, bool> > queryExpression) { using (FlightContext dbContext = new FlightContext()) { return(dbContext.Flights.Where(queryExpression).Where(_ => _.IsValid)); } }
public bool IsValid(string club) { using (var shortDb = new FlightContext()) { return(shortDb.Clubs.Any(d => d.ShortName == club)); } }
public Flight QueryFlightByFlightNumber(string flightNumber) { using (FlightContext dbContext = new FlightContext()) { return(dbContext.Flights.Where(_ => _.FlightNumber == flightNumber && _.IsValid == true).FirstOrDefault()); } }
public async Task <ActionResult> RemovePilotBinding(string currentPilotIdBinding) { ManageMessageId?message = ManageMessageId.Error; var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { using (var context = new FlightContext()) { if (user.BoundToPilotId != null) { var userPilotBinding = context.Pilots.Find(Convert.ToInt32(user.BoundToPilotId)); if (userPilotBinding.PilotId.ToString(CultureInfo.InvariantCulture) == currentPilotIdBinding) { using (var db = new ApplicationDbContext()) { var dbUser = db.Users.Find(user.Id); if (dbUser != null) { dbUser.BoundToPilotId = null; db.SaveChanges(); message = ManageMessageId.RemovePilotBindingSuccess; } } } } } } return(RedirectToAction("ManagePilotBinding", new { Message = message })); }
public AuthUsersController(FlightContext context, UserManager <AuthUser> userManager, SignInManager <AuthUser> signManager, RoleManager <ApplicationRole> roleManager) { _context = context; _userManager = userManager; _signManager = signManager; _roleManager = roleManager; }
public async Task <ActionResult> LinkPilot(string pilot) { ManageMessageId?message = ManageMessageId.Error; var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { using (var context = new FlightContext()) { var userPilotBinding = context.Pilots.Find(Convert.ToInt32(pilot)); if (userPilotBinding != null) { // Validate User and Pilot have Email or Phone Number in Common using (var db = new ApplicationDbContext()) { var dbUser = db.Users.Find(user.Id); if (dbUser != null) { dbUser.BoundToPilotId = userPilotBinding.PilotId.ToString(CultureInfo.InvariantCulture); db.SaveChanges(); message = ManageMessageId.BindToPilotSuccess; } } } } } return(RedirectToAction("ManagePilotBinding", new { Message = message })); }
//Makes a list that contains all Flights in the Database public List <Flight> GetAll() { using (context = new FlightContext()) { return(context.Flights.ToList()); } }
public static List <Pilot> FindPilotsByEmail(string email) { email = ParseEmail(email); using (var shortDb = new FlightContext()) { return(shortDb.Pilots.Where(d => d.Email == email).ToList()); } }
public void UpdateFlight(Flight flight) { using (FlightContext dbContext = new FlightContext()) { dbContext.Update <Flight>(flight); dbContext.SaveChanges(); } }
public FlightsController( FlightContext dbContext, FlightExtentions flights ) { _dbContext = dbContext; _flights = flights; }
public FlightPlansController(FlightContext flightContext, IFlightManager flightManager, IFlightPlanManager flightPlanManager, IHttpClientFactory clientFactory) { _flightContext = flightContext; _flightPlanManager = flightPlanManager; _flightManager = flightManager; _clientFactory = clientFactory; }
public IEnumerable < Flight >> GetAllFlights() { using (var flightContext = new FlightContext()) { var flights = flightContext.Flights.ToList(); return(flights); } }
public void FlightUpdate(Flight flight) { using (FlightContext db = new FlightContext()) { db.Entry(flight).State = EntityState.Modified; db.SaveChanges(); } }
public void PassEdit(Passenger passenger) { using (FlightContext db = new FlightContext()) { db.Entry(passenger).State = EntityState.Modified; db.SaveChanges(); } }
public void FlightAdd(Flight flight) { using (FlightContext db = new FlightContext()) { db.Flights.Add(flight); db.SaveChanges(); } }
public static List <Pilot> FindPilotsByMobilNumber(string mobilNumber) { mobilNumber = ParseMobilNumber(mobilNumber); using (var shortDb = new FlightContext()) { return(shortDb.Pilots.Where(d => d.MobilNumber == mobilNumber).ToList()); } }
public void PassAdd(Passenger passenger) { using (FlightContext db = new FlightContext()) { db.Passengers.Add(passenger); db.SaveChanges(); } }
public IEnumerable <Flight> GetAllFlights() { using (var flightContext = new FlightContext()) { var flights = flightContext.Flights.Include(f => f.Travelers).ToList(); return(flights); } }
public void PassDelete(Passenger passenger) { using (FlightContext db = new FlightContext()) { db.Passengers.Attach(passenger); db.Entry(passenger).State = EntityState.Deleted; db.SaveChanges(); } }
public FlightsControllerTests() { string[] args = { }; var d = new DbContextOptionsBuilder <FlightContext>(); var h = Program.CreateHostBuilder(args); d.UseInMemoryDatabase("DBName"); _FlightDBContextMock = new FlightContext(d.Options); fpc = new FlightPlanController(_FlightDBContextMock); }
static void Main(string[] args) { var flightContext = new FlightContext(""); Console.Write(flightContext.ToDotGraph()); TextCopy.ClipboardService.SetText(flightContext.ToDotGraph()); Console.ReadKey(); }
public ActionResult RemoveFlight(Flight flight) { using (flightContext = new FlightContext()) { Flight toRemove = flightContext.Flights.Find(flight.Id); flightContext.Flights.Remove(toRemove); flightContext.SaveChanges(); return(View("~/Views/Admin/Home.cshtml")); } }
public void Delete(Flight flight) { using (FlightContext dbContext = new FlightContext()) { flight.IsValid = false; flight.UpdateTime = DateTime.Now; dbContext.Update <Flight>(flight); dbContext.SaveChanges(); } }
public void FlightDelete(Flight flight) { using (FlightContext db = new FlightContext()) { db.Flights.Attach(flight); db.Passengers.RemoveRange(flight.Passengers); db.Entry(flight).State = EntityState.Deleted; db.SaveChanges(); } }
/// <summary> /// Method that reads from file all airports and saves in appropriate table. /// </summary> /// <param name="FlightContext">EntityFramework Flights Context</param> public static void SeedAirports(FlightContext context, ILogger logger) { if (!context.Airports.Any()) { var airportData = System.IO.File.ReadAllText("Migrations/SeedData/airports.json"); var airports = JsonConvert.DeserializeObject <IList <Airport> >(airportData); context.AddRange(airports); context.SaveChanges(); } }
// ToDo: Add information about the aircrafts climbrate and so on, if possible internal static PositionUpdate NormalizeData(FlightContext context, PositionUpdate position) { if (position == null || context.Flight.PositionUpdates.Count < 2 || (!double.IsNaN(position.Heading) && !double.IsNaN(position.Speed))) { return(position); } var previousPosition = context.Flight.PositionUpdates.LastOrDefault(); if (previousPosition == null) { return(position); } double?heading = null; double?speed = null; if (double.IsNaN(position.Heading)) { heading = Geo.DegreeBearing(previousPosition.Location, position.Location); } if (double.IsNaN(position.Speed)) { // 1. Get the distance (meters) // 2. Calculate the time difference (seconds) // 3. Convert to knots (1.94384449 is a constant) var distance = previousPosition.Location.DistanceTo(position.Location); double timeDifference = (position.TimeStamp - previousPosition.TimeStamp).Milliseconds; if (timeDifference < 50) { return(null); } if (distance != 0) { speed = distance / (timeDifference / 1000) * 1.94384449; } else { speed = 0; } } position.Speed = speed ?? position.Speed; position.Heading = heading ?? position.Heading; return(position); }
public ActionResult RemoveFlight(int id = 0) { using (FlightContext flightContext = new FlightContext()) { Flight flight = flightContext.Flights.First(x => x.Id == id); if (flight == null) { return(View("~/Views/Home/Index.cshtml")); } return(View(flight)); } }
public void BookFlight(int flightId, [FromBody] IEnumerable <Traveler> travelers) { using (var flightContext = new FlightContext()) { var flight = flightContext.Flights.FirstOrDefault(f => f.FlightId == flightId); if (flight != null) { flight.Travelers = travelers.ToList(); flightContext.SaveChanges(); } } }