Exemplo n.º 1
0
        public IActionResult BookingReturn()
        {
            // Agarrar o modelo
            var data = TempData.Get <ChooseSeatFlightModel>("BookingRetun");

            if (data == null)
            {
                return(NotFound());
            }

            ChooseSeatFlightModel model = new ChooseSeatFlightModel();

            //========= Bilhete de Ida============
            model.Classes               = data.Classes;
            model.FlightId              = data.FlightId;
            model.FlightIdReturn        = data.FlightIdReturn;
            model.Class                 = data.Class;
            model.Seat                  = data.Seat;
            model.SeatReturn            = data.SeatReturn;
            model.SeatIsAvailable       = data.SeatIsAvailable;
            model.SeatIsAvailableReturn = data.SeatIsAvailableReturn;
            model.isRoundTrip           = data.isRoundTrip;

            return(View(model));
        }
Exemplo n.º 2
0
        public IActionResult Booking(ChooseSeatFlightModel model)
        {
            if (model == null)
            {
                return(NotFound());
            }

            ChooseSeatFlightModel newModel = new ChooseSeatFlightModel();

            newModel.FlightId       = model.FlightId;
            newModel.FlightIdReturn = model.FlightIdReturn;
            newModel.isRoundTrip    = model.isRoundTrip;
            newModel.Seat           = model.Seat;
            newModel.Class          = model.Class;
            newModel.Classes        = _flightRepository.GetComboClasses();

            if (model.isRoundTrip == 1) // Is RoundTrip
            {
                var flightReturn = _flightRepository.GetFlight(model.FlightIdReturn);

                if (flightReturn == null)
                {
                    return(NotFound());
                }

                // Criar a lista com as classes para passar para a view
                string[] TicketsClassArrayReturn = new string[64];

                List <int> TicketsClassListReturn = new List <int>(); // 8 Executiva + 56 Económica = 64 lugares

                // Obter a lista de bilhetes existentes para o voo de regresso
                var ticketsListReturn = _ticketRepository.FlightTickets(flightReturn.Id);


                foreach (var item in ticketsListReturn)
                {
                    int index = (item.Seat) - 1;

                    TicketsClassArrayReturn[index] = "occupied";
                }

                newModel.FlightIdReturn        = flightReturn.Id;
                newModel.SeatIsAvailableReturn = TicketsClassArrayReturn.ToList();
            }



            // Redireccionar para o booking (levar o modelo)
            TempData.Put("BookingRetun", newModel);

            if (model.isRoundTrip == 1)
            {
                return(RedirectToAction("BookingReturn", "Home"));
            }

            return(RedirectToAction("TicketNew", "Home"));
        }
Exemplo n.º 3
0
        public IActionResult BookingReturn(ChooseSeatFlightModel model)
        {
            if (model == null)
            {
                return(NotFound());
            }

            // Redireccionar para o booking (levar o modelo)
            TempData.Put("BookingRetun", model);

            return(RedirectToAction("TicketNew", "Home"));
        }
Exemplo n.º 4
0
        public IActionResult ViewFlights(ShowListFlightsModel model)
        {
            if (ModelState.IsValid)
            {
                ChooseSeatFlightModel chooseSeatFlight = new ChooseSeatFlightModel();

                // 1º: Obter a lista das classes
                var list = _flightRepository.GetComboClasses(); // Obter as classes

                //2ª O cliente escolheu ida e volta?

                chooseSeatFlight.isRoundTrip = model.isRoundTrip;


                // 3º: Verificar a existência do voo de ida
                var flight = _flightRepository.GetFlight(model.flightId);



                if (flight == null)
                {
                    return(this.RedirectToAction("Index"));
                }


                //4º: Obter a lista de bilhetes existentes para o voo de ida
                var ticketsList = _ticketRepository.FlightTickets(model.flightId);


                // 4º Criar a lista com as classes para passar para a view
                string[] TicketsClassArray = new string[64];

                foreach (var item in ticketsList)
                {
                    int index = (item.Seat) - 1;

                    TicketsClassArray[index] = "occupied";
                }

                ////=====================Flight Return================

                if (model.isRoundTrip == 1)
                {
                    var flightReturn = _flightRepository.GetFlight(model.flightIdReturn);

                    if (flightReturn == null)
                    {
                        return(NotFound());
                    }

                    chooseSeatFlight.FlightIdReturn = flightReturn.Id;
                }

                //======================Fim Flight Return===================================

                chooseSeatFlight.FlightId        = flight.Id;
                chooseSeatFlight.Classes         = list;
                chooseSeatFlight.SeatIsAvailable = TicketsClassArray.ToList();


                // Redireccionar para o booking (levar o modelo)
                TempData.Put("Booking", chooseSeatFlight);
                return(RedirectToAction("Booking", "Home"));
            }

            return(View(model));
        }