Ejemplo n.º 1
0
        public void AddSeatsForFlight(Flight flight, int row, int col, SeatClass seatClass)
        {
            using (var context = new ABS())
            {
                // Gets the section for the enum seatClass
                var section = context.Sections.Where(s => s.SeatClassName == seatClass.ToString())
                              .FirstOrDefault();

                // Checks if such section is already associated with the flight
                var existingSection = context.Seats.Where(s => s.FlightId == flight.FlightId && s.SectionId == section.SectionId)
                                      .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  = flight.FlightId;
                        seatToAdd.Status    = true;
                        seatToAdd.SectionId = section.SectionId;
                        seats.Add(seatToAdd);
                    }
                }
                context.Seats.AddRange(seats);
                context.SaveChanges();
            }
        }
Ejemplo n.º 2
0
 public ThankYouViewModel(string bookingId, SeatClass seatClass, int selectedRow, int selectedCol)
 {
     SelectedClass      = seatClass.ToString();
     SelectedRow        = selectedRow.ToAlphabet();
     SelectedCol        = (selectedCol + 1).ToString();
     BookingSucceedText = "Congraduration! Your booking id is " + bookingId + ".";
 }
Ejemplo n.º 3
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);
            }
        }