// GET: Destinations/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var destination = await _repository.GetDestinationWithUserCityAndCoutryAsync(id.Value); // .Value é obrigatório pois o id pode ser nulo if (destination == null) { return(NotFound()); } return(View(destination)); }
public async Task <IActionResult> Index() { var model = new FlightViewModel() { States = _flightRepository.GetComboStatus(), // Apresentar uma combobox com os estado dos voos para posteriormente apresentar os voos na tabela Flights = _flightRepository.GetAllWithObjects(), }; foreach (var item in model.Flights) { var destinationFrom = await _destinationRepository.GetDestinationWithUserCityAndCoutryAsync(item.From.Id); var destinationTo = await _destinationRepository.GetDestinationWithUserCityAndCoutryAsync(item.To.Id); item.From = destinationFrom; item.To = destinationTo; } return(View(model)); }
public async Task <IActionResult> MyFlights() { string email = this.User.Identity.Name; List <Ticket> MyList = new List <Ticket>(); MyList = _ticketRepository.FlightTicketsByUser(email); foreach (var item in MyList) { Destination cityFrom = await _destinationRepository.GetDestinationWithUserCityAndCoutryAsync(item.Flight.From.Id); Destination cityTo = await _destinationRepository.GetDestinationWithUserCityAndCoutryAsync(item.Flight.To.Id); item.Flight.From.City.Name = cityFrom.City.Name; item.Flight.To.City.Name = cityTo.City.Name; } return(View(MyList)); }
[Authorize] // POde ser camado do booking ou do boobking return public async Task <IActionResult> TicketNew() { // Agarrar o modelo var data = TempData.Get <ChooseSeatFlightModel>("BookingRetun"); if (data == null) { return(NotFound()); } NewTicketModel model = new NewTicketModel(); string email = this.User.Identity.Name; User user = await _userHelper.GetUserByEmailAsync(email); Flight flight = await _flightRepository.GetFlightWithObjectsAsync(data.FlightId); Destination From = await _destinationRepository.GetDestinationWithUserCityAndCoutryAsync(flight.From.Id); Destination To = await _destinationRepository.GetDestinationWithUserCityAndCoutryAsync(flight.To.Id); model.FullName = user.FullName; model.UserEmail = user.Email; //======== Bilhete de Ida ========// model.FlightId = flight.Id; model.From = From.City.Name; model.To = To.City.Name; model.Date = flight.Departure.ToShortDateString(); model.Time = flight.Departure.ToShortTimeString(); model.Seat = data.Seat.ToString(); if (data.Class == 1) { model.ClassName = "Economic"; } else if (data.Class == 2) { model.ClassName = "Business"; } if (data.isRoundTrip == 1) // Ida e Volta { Flight flightReturn = await _flightRepository.GetFlightWithObjectsAsync(data.FlightIdReturn); //======== Bilhete de Volta ========// model.FlightIdReturn = flightReturn.Id; model.FromReturn = To.City.Name; model.ToReturn = From.City.Name; model.DateReturn = flightReturn.Departure.ToShortDateString(); model.TimeReturn = flightReturn.Departure.ToShortTimeString(); model.SeatReturn = data.SeatReturn.ToString(); if (data.ClassReturn == 1) { model.ClassNameReturn = "Economic"; } else if (data.ClassReturn == 2) { model.ClassNameReturn = "Business"; } } return(View(model)); }