示例#1
0
 /// <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();
     }
 }
示例#2
0
 /// <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();
     }
 }
示例#3
0
 /// <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();
     }
 }
示例#4
0
 /// <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();
     }
 }
示例#5
0
        /// <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);
        }
示例#6
0
        /// <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);
        }
示例#7
0
        /// <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);
        }
示例#8
0
        /// <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);
        }
示例#9
0
        /// <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);
        }
示例#10
0
        /// <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);
        }
示例#11
0
        /// <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);
        }