/// <summary> /// Adds a new airplane to the context and saves it to the db /// </summary> /// <param name="airplane"></param> public void CreateAirplane(Airplane airplane) { using (var context = new AirplanesEntities()) { context.Airplanes.Add(airplane); context.SaveChanges(); } }
/// <summary> /// Creates a country from a country object /// </summary> /// <param name="name"></param> public void CreateCountry(Country country) { using (var context = new AirplanesEntities()) { context.Countrys.Add(country); context.SaveChanges(); } }
/// <summary> /// removes an airplane by the model /// and saves the changes to the db /// </summary> /// <param name="airplane"></param> public void RemoveAirplane(Airplane airplane) { using (var context = new AirplanesEntities()) { context.Entry(airplane).State = System.Data.Entity.EntityState.Deleted; context.Airplanes.Remove(airplane); context.SaveChanges(); } }
/// <summary> /// Removes a country by name /// </summary> /// <param name="name"></param> public void RemoveCountry(Country country) { using (var context = new AirplanesEntities()) { context.Entry(country).State = System.Data.Entity.EntityState.Deleted; context.Countrys.Remove(country); context.SaveChanges(); } }
/// <summary> /// Searches an airplane by the current airport and the next /// </summary> /// <param name="currentPos"></param> /// <param name="nextPos"></param> /// <returns></returns> public Airplane SearchAirplaneByCurrentAndDestination(Airport currentPos, Airport nextPos) { Airplane airplane; using (var context = new AirplanesEntities()) { airplane = context.Airplanes.Where((obj) => obj.Airport == currentPos && obj.Airport1 == nextPos).FirstOrDefault(); } return(airplane); }
/// <summary> /// Get all the countries /// </summary> /// <returns></returns> public List <Country> GetAllCountries() { List <Country> countries = new List <Country>(); using (var context = new AirplanesEntities()) { countries = context.Countrys.ToList(); } return(countries); }
/// <summary> /// Search multiple airports by country /// </summary> /// <param name="country"></param> /// <returns></returns> public List <Airport> SearchAirportsByCountry(Country country) { List <Airport> airports = new List <Airport>(); using (var context = new AirplanesEntities()) { airports = context.Airports.Where((obj) => obj.Country == country).ToList(); } return(airports); }
/// <summary> /// Search an airport by name /// </summary> /// <param name="name"></param> /// <returns></returns> public Airport SearchAirportByName(string name) { Airport airport; using (var context = new AirplanesEntities()) { airport = context.Airports.Where((obj) => obj.Name.Contains(name)).FirstOrDefault(); } return(airport); }
/// <summary> /// Get all the airports /// </summary> /// <returns></returns> public List <Airport> GetAllAirports() { List <Airport> airports = new List <Airport>(); using (var context = new AirplanesEntities()) { airports = context.Airports.ToList(); } return(airports); }
/// <summary> /// Get all the airlines /// </summary> /// <returns></returns> public List <Airline> GetAirlines() { List <Airline> airlines = new List <Airline>(); using (var context = new AirplanesEntities()) { airlines = context.Airlines.ToList(); } return(airlines); }
/// <summary> /// Get all the airplanes and the underlying children /// </summary> /// <returns></returns> public List <Airplane> GetAirplanes() { List <Airplane> airplanes = new List <Airplane>(); using (var context = new AirplanesEntities()) { airplanes = context.Airplanes .Include((obj) => obj.Airline) .Include((obj) => obj.Airport) .Include((obj) => obj.Airport1).ToList(); } return(airplanes); }