예제 #1
0
        public FlightEntity SaveFlightEntity(FlightEntity flight)
        {
            using (var context = new TUIAssessmentDALContext(_options))
            {
                context.Flights.Add(flight);
                context.SaveChanges();
            }

            return(flight);
        }
예제 #2
0
        public IEnumerable <FlightEntity> GetFlightEntities()
        {
            var flights = new List <FlightEntity>();

            using (var context = new TUIAssessmentDALContext(_options))
            {
                flights = context.Flights.ToList();
            }

            return(flights);
        }
예제 #3
0
        public FlightEntity GetFlightEntityByID(int Id)
        {
            FlightEntity flight = null;

            using (var context = new TUIAssessmentDALContext(_options))
            {
                flight = context.Flights.Single(f => f.Id == Id);
            }

            return(flight);
        }
예제 #4
0
        public IEnumerable <AirportEntity> GetAirportEntities()
        {
            var airports = new List <AirportEntity>();

            using (var context = new TUIAssessmentDALContext(_options))
            {
                airports = context.Airports.ToList();
            }

            return(airports);
        }
예제 #5
0
        public AirportEntity GetAirportEntityByID(int Id)
        {
            AirportEntity airport = null;

            using (var context = new TUIAssessmentDALContext(_options))
            {
                airport = context.Airports.Single(a => a.Id == Id);
            }

            return(airport);
        }
예제 #6
0
        public bool RemoveFlightEntityByID(int Id)
        {
            var count = 0;

            using (var context = new TUIAssessmentDALContext(_options))
            {
                var flight = context.Flights.Single(f => f.Id == Id);
                if (flight != null)
                {
                    context.Flights.Remove(flight);
                    count = context.SaveChanges();
                }
            }

            return(count == 1);
        }
예제 #7
0
        public FlightEntity UpdateFlightEntity(FlightEntity flight)
        {
            using (var context = new TUIAssessmentDALContext(_options))
            {
                var flightInDB = context.Flights.Single(f => f.Id == flight.Id);

                if (flightInDB != null)
                {
                    flightInDB.ArrivalAirportId   = flight.ArrivalAirportId;
                    flightInDB.DepartureAirportId = flight.DepartureAirportId;
                    flightInDB.Distance           = flight.Distance;
                    flightInDB.FuelQuantity       = flight.FuelQuantity;
                    flightInDB.TimeOfFlight       = flight.TimeOfFlight;
                    flightInDB.Update             = DateTime.Now;
                }

                context.SaveChanges();
            }

            return(GetFlightEntityByID(flight.Id));
        }