Esempio n. 1
0
        public void AddSeatsForFlight(int flightId, int row, int col, int seatClassId)
        {
            using (var context = new ABS())
            {
                // Checks if such section is already associated with the flight
                var existingSection = context.Seats.Where(s => s.FlightId == flightId && s.SectionId == seatClassId)
                                      .FirstOrDefault();
                if (existingSection != null)
                {
                    throw new Exception(ExceptionHelper.ExistingSection);
                }

                List <Seat> seats = new List <Seat>();
                for (int i = 0; i < row; i++)
                {
                    for (int j = 0; j < col; j++)
                    {
                        Seat seatToAdd = new Seat();
                        seatToAdd.Col       = Convert.ToChar('A' + j).ToString(); //translates the integer value to alphabethical char
                        seatToAdd.Row       = i + 1;                              //because we want the rows to start at 1 not at 0
                        seatToAdd.FlightId  = flightId;
                        seatToAdd.Status    = true;
                        seatToAdd.SectionId = seatClassId;
                        seats.Add(seatToAdd);
                    }
                }
                context.Seats.AddRange(seats);
                context.SaveChanges();
            }
        }
Esempio n. 2
0
        public void AddNewAirline(Airline airline)
        {
            using (var context = new ABS())
            {
                var airline1 = context.Airlines.Where(a => a.Name == airline.Name).FirstOrDefault();
                if (airline1 != null)
                {
                    throw new Exception(ExceptionHelper.AlreadyExistentAirline);
                }

                context.Airlines.Add(airline);
                context.SaveChanges();
            }
        }
Esempio n. 3
0
 public void AddNewAirport(Airport airport)
 {
     using (var context = new ABS())
     {
         // Tries to find airport with the same name as the passed entity and adds it to the database only if it is not found
         var airp = context.Airports.Where(a => a.Name == airport.Name).FirstOrDefault();
         if (airp != null)
         {
             throw new Exception(ExceptionHelper.AlreadyExistentAirport);
         }
         context.Airports.Add(airport);
         context.SaveChanges();
     }
 }
Esempio n. 4
0
        /*public bool BookSeat(Flight flight, SeatClass seatClass, int row, string col)
         * {
         *  using (var context = new ABS())
         *  {
         *      var section = context.Sections.Where(s => s.SeatClassName == seatClass.ToString())
         *                                    .FirstOrDefault();
         *      var seatToBook = context.Seats.Where(s => s.FlightId == flight.FlightId
         *                                             && s.SectionId == section.SectionId
         *                                             && s.Row == row
         *                                             && s.Col == col)
         *                                    .FirstOrDefault();
         *
         *      if (seatToBook.Status == false)
         *          return false;
         *      seatToBook.Status = false;
         *      context.SaveChanges();
         *
         *      return true;
         *  }
         * }*/
        public bool BookSeat(int seatId)
        {
            using (var context = new ABS())
            {
                var seat = context.Seats.Where(s => s.SeatId == seatId).FirstOrDefault();
                if (seat.Status == false)
                {
                    return(false);
                }
                seat.Status = false;
                context.SaveChanges();

                return(true);
            }
        }
Esempio n. 5
0
 public void AddNewFlight(Flight flight)
 {
     using (var context = new ABS())
     {
         var flight1 = context.Flights.Where(f => f.AirlineId == flight.AirlineId && f.FlightName == flight.FlightName)
                       .FirstOrDefault();
         if (flight1 != null)
         {
             throw new Exception(ExceptionHelper.AlreadyExistentFlight);
         }
         if (flight.OrgAirportId == flight.DestAirportId)
         {
             throw new Exception(ExceptionHelper.SameOriginAndDestination);
         }
         context.Flights.Add(flight);
         context.SaveChanges();
     }
 }