Пример #1
0
        public async Task <IActionResult> Index(SearchFlightModel model)
        {
            if (ModelState.IsValid)
            {
                var destinationFrom = await _destinationRepository.GetDestinationByNameAsync(model.From);

                //Confirmar a existência das cidades
                if (destinationFrom == null)
                {
                    this.ModelState.AddModelError(string.Empty, "Destination From does not exist!");
                    return(View(model));
                }

                var destinationTo = await _destinationRepository.GetDestinationByNameAsync(model.To);

                //Confirmar a existência das cidades
                if (destinationTo == null)
                {
                    this.ModelState.AddModelError(string.Empty, "Destination To does not exist!");
                    return(View(model));
                }

                ShowListFlightsModel modelView = new ShowListFlightsModel();
                modelView.Flights = _flightRepository.GetFlightsFromToAndDeparture(model.From, model.To, model.Departure);

                if (modelView.Flights.Count == 0)
                {
                    this.ModelState.AddModelError(string.Empty, "There are no flights from the selected airport!");
                    return(View(model));
                }

                modelView.isRoundTrip = 2; // One-Way

                if (model.Trip == 1)       // Roundtrip
                {
                    modelView.FlightsReturn = _flightRepository.GetFlightsFromToAndDeparture(model.To, model.From, model.Return);
                    modelView.isRoundTrip   = 1;

                    if (modelView.FlightsReturn.Count == 0)
                    {
                        modelView.isRoundTrip = 1;
                        this.ModelState.AddModelError(string.Empty, "There are no flights from the return airport!");
                        return(View(model));
                    }
                }
                // Redireccionar para o booking (levar o modelo)
                TempData.Put("FlightsList", modelView);
                return(RedirectToAction("ViewFlights", "Home"));
            }

            return(View(model));
        }
Пример #2
0
        public IActionResult ViewFlights()
        {
            // Agarrar o modelo

            var data = TempData.Get <ShowListFlightsModel>("FlightsList");

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

            ShowListFlightsModel model = new ShowListFlightsModel();

            model.flightId       = data.flightId;
            model.flightIdReturn = data.flightIdReturn;
            model.Flights        = data.Flights;
            model.FlightsReturn  = data.FlightsReturn;
            model.isRoundTrip    = data.isRoundTrip;

            return(View(model));
        }
Пример #3
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));
        }