コード例 #1
0
        public async Task <IActionResult> ShowTicket(TicketModelCreate model)
        {
            if (ModelState.IsValid)
            {
                User user = await _userHelper.GetUserByEmailAsync(model.UserEmail);

                model.FullName = user.FullName;

                if (model.Class == 1)
                {
                    model.ClassName = "Economic";
                }

                else if (model.Class == 2)
                {
                    model.ClassName = "Business";
                }

                var flight = await _flightRepository.GetFlightWithObjectsAsync(model.FlightId);

                Destination fromDestination = await _destinationRepository.GetDestinationByIATAAsync(flight.From.IATA);

                Destination toDestination = await _destinationRepository.GetDestinationByIATAAsync(flight.To.IATA);

                model.From = fromDestination.City.Name;
                model.To   = toDestination.City.Name;
                model.Date = flight.Departure.ToShortDateString();
                model.Time = flight.Departure.ToShortTimeString();
                return(View(model));
            }

            return(this.RedirectToAction("Index", "Flights"));
        }
コード例 #2
0
        public async Task <IActionResult> ConfirmTicket(TicketModelCreate model)
        {
            if (ModelState.IsValid)
            {
                Ticket ticket = new Ticket();

                User user = await _userHelper.GetUserByEmailAsync(model.UserEmail);

                Flight flight = _flightRepository.GetFlight(model.FlightId);

                ticket.Seat   = model.Seat;
                ticket.User   = user;
                ticket.Flight = flight;

                if (model.Class == 1)
                {
                    ticket.Class = "Economic";
                }

                if (model.Class == 2)
                {
                    ticket.Class = "Business";
                }

                try
                {
                    await _ticketRepository.CreateAsync(ticket);// Ao usar o create grava logo

                    var myToken = await _userHelper.GenerateEmailConfirmationTokenAsync(user);

                    // Criar um link que vai levar lá dentro uma acção. Quando o utilizador carregar neste link,
                    // vai no controlador Account executar a action "ConfirmEmail"(Ainda será feita)
                    // Este ConfirmEmail vai receber um objecto novo que terá um userid e um token.
                    var tokenLink = this.Url.Action("Index", "Home", new
                    {
                        userid = user.Id,
                        token  = myToken,
                    }, protocol: HttpContext.Request.Scheme);

                    _mailHelper.SendMail(model.UserEmail, "Ticket", $"<h1>Ticket Confirmation</h1>" +
                                         $"Your ticket information, " +
                                         $"Flight: {model.FlightId}, " +
                                         $"Class: {ticket.Class}, " +
                                         $"Date: {ticket.Seat}, " +
                                         $"Click in this link to home page :</br></br><a href = \"{tokenLink}\">Airline</a>");


                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.InnerException.Message);
                    return(View(model));
                }
            }

            return(this.RedirectToAction("Index", "Flights"));
        }
コード例 #3
0
        public async Task <IActionResult> Booking(TicketModelCreate model)
        {
            // 1º: Obter a lista das classes
            var list = _flightRepository.GetComboClasses();     // Obter as classes

            // 2º: Verificar a existência do user
            var user = await _userHelper.GetUserByEmailAsync(model.UserEmail);

            if (user == null)
            {
                return(this.RedirectToAction("Index", "Flights"));
            }

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

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

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


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

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



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

                TicketsClassArray[index] = "occupied";
            }



            model.UserEmail       = user.Email;
            model.FlightId        = flight.Id;
            model.Classes         = list;
            model.SeatIsAvailable = TicketsClassArray.ToList();
            return(View(model));
        }
コード例 #4
0
        // GET: Tickets/Create/5
        public async Task <IActionResult> CreateTicket(int?id) // FlightId
        {
            if (id == null)
            {
                return(NotFound());
            }

            // Obter o voo
            var flight = await _flightRepository.GetFlightWithObjectsAsync(id.Value);


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


            if (flight.Status.StatusName == "Canceled" || flight.Status.StatusName == "Concluded")
            {
                ViewBag.Message = "The flight isn't active! It´s impossible to create tickets!";
                return(View());
            }
            //Obter os bilhetes do voo, se houverem voos disponiveis é encaminhado para a escolha do cliente

            var tickets = _flightRepository.GetTickets(id.Value);


            // Existem bilhetes disponíveis, escolher o cliente:

            TicketModelCreate model = new TicketModelCreate();

            List <User> users = _userHelper.GetAllUsers();

            model.Users    = users;
            model.FlightId = flight.Id;

            return(View(model));
        }