public void AddAirline(string airlineName)
 {
     context.Airlines.Add(new Airline {
         AirlineName = airlineName
     });
     context.SaveChanges();
 }
 public void AddAirport(string airportName)
 {
     context.Airports.Add(new Airport {
         AirportName = airportName
     });
     context.SaveChanges();
 }
        public void AddSectionTypes()
        {
            using (BookingSystemDbContext context = new BookingSystemDbContext())
            {
                if (!context.FlightSectionTypes.Where(x => x.FlightSectionName == "First").Any())
                {
                    FlightSectionType first = new FlightSectionType()
                    {
                        FlightSectionName = "First"
                    };
                    context.FlightSectionTypes.Add(first);
                }
                if (!context.FlightSectionTypes.Where(x => x.FlightSectionName == "Economy").Any())
                {
                    FlightSectionType economy = new FlightSectionType()
                    {
                        FlightSectionName = "Economy"
                    };
                    context.FlightSectionTypes.Add(economy);
                }
                if (!context.FlightSectionTypes.Where(x => x.FlightSectionName == "Business").Any())
                {
                    FlightSectionType business = new FlightSectionType()
                    {
                        FlightSectionName = "Business"
                    };
                    context.FlightSectionTypes.Add(business);
                }

                context.SaveChanges();
            }
        }
Exemple #4
0
        public void AddSection(string airlineName, string flightId, int rows, int cols, string sectionType)
        {
            Airline targetAirline = context.Airlines.Where(x => x.AirlineName == airlineName).FirstOrDefault();
            Flight  targetFlight  = targetAirline.Flights.Where(x => x.FlightId == flightId).FirstOrDefault();
            var     flightSection = targetFlight.FlightSections.Where(x => x.FlightSectionType.FlightSectionName == sectionType).FirstOrDefault();


            if (targetAirline != null)
            {
                if (targetFlight != null)
                {
                    //if no such class in the flight exists,create one
                    if (flightSection == null)
                    {
                        HashSet <Seat> sectionSeats = new HashSet <Seat>();
                        for (int i = 1; i <= rows; i++)
                        {
                            for (int j = 1; j <= cols; j++)
                            {
                                sectionSeats.Add(new Seat()
                                {
                                    Row = i, Column = j, IsTaken = false
                                });
                            }
                        }
                        var section = context.FlightSectionTypes.Where(x => x.FlightSectionName == sectionType).FirstOrDefault();
                        targetFlight.FlightSections.Add(new FlightSection()
                        {
                            Seats = sectionSeats, FlightSectionType = section
                        });
                    }
                    context.SaveChanges();
                }
            }
        }
Exemple #5
0
        public void BookSeat(string airline, string flightId, string seatType, int row, int col)
        {
            Airline       targetAirline       = context.Airlines.Where(a => a.AirlineName == airline).SingleOrDefault();
            Flight        targetFlight        = targetAirline.Flights.Where(f => f.FlightId == flightId).FirstOrDefault();
            FlightSection targetFlightSection = targetFlight.FlightSections.Where(s => s.FlightSectionType.FlightSectionName == seatType).FirstOrDefault();
            Seat          targetSeat          = targetFlightSection.Seats.Where(seat => seat.Row == row && seat.Column == col && seat.IsTaken == false).FirstOrDefault();

            targetSeat.IsTaken = true;
            context.SaveChanges();
        }
Exemple #6
0
        public void AddFlight(string airlineName, string origin, string destination, int year, int month, int day, string flightId)
        {
            Airline targetAirline      = context.Airlines.Where(x => x.AirlineName == airlineName).FirstOrDefault();
            Airport originAirport      = context.Airports.Where(x => x.AirportName == origin).FirstOrDefault();
            Airport destinationAirport = context.Airports.Where(x => x.AirportName == destination).FirstOrDefault();
            Flight  targetFlight       = targetAirline.Flights.Where(x => x.FlightId == flightId).FirstOrDefault();

            context.Flights.Add(new Flight()
            {
                Airline = targetAirline, Origin = originAirport, Destination = destinationAirport, FlightId = flightId, DepartureDate = new DateTime(year, month, day)
            });
            context.SaveChanges();
        }
 public void Save()
 {
     context.SaveChanges();
 }