コード例 #1
0
        /// <summary>
        /// Index and login page without post
        /// </summary>
        /// <returns>Login view</returns>
        public IActionResult Index()
        {
            if (!sessions.Exist("UserId"))
            {
                return(View(new Login()));
            }

            messagesHandler.Add("warning", "You are already login!");

            return(RedirectToAction("Index", "Users"));
        }
コード例 #2
0
        public ActionResult Booking(FlightSearch flightSearch)
        {
            List <TicketVariables> tickets = new List <TicketVariables>();

            try
            {
                List <Flight> flightsAirportDate = ticketApi.GetFlightsByAirportDate(flightSearch.From, flightSearch.DepartureDay.ToString("yyyyMMdd"));
                List <Flight> customersChoice    = new List <Flight>();

                string airPortFromName        = "";
                string airPortDestinationName = "";

                foreach (AirPort airport in ticketApi.GetAirPorts())
                {
                    if (airport.ID == flightSearch.From)
                    {
                        airPortFromName = airport.Name;
                    }
                    if (airport.ID == flightSearch.Destination)
                    {
                        airPortDestinationName = airport.Name;
                    }
                }

                int seatNumber = 0;


                foreach (Flight flight in flightsAirportDate)
                {
                    if (flight.ArrivalPort == flightSearch.Destination)
                    {
                        customersChoice.Add(flight);
                    }
                }

                foreach (Flight flight in customersChoice)
                {
                    seatNumber = ticketApi.GetFlightSeats(flight.Id)[0];
                    tickets.Add(new TicketVariables
                    {
                        From      = airPortFromName,
                        To        = airPortDestinationName,
                        SeatNum   = seatNumber,
                        Departure = flight.DepartureDate,
                        Arrival   = flight.ArrivalDate,
                        Price     = flight.Price
                    });
                }

                if (tickets.Count > 0)
                {
                    return(View("Booking", tickets));
                }
                else
                {
                    messagesHandler.Add("warning", "No flights available");
                }
            }
            catch (Exception ex)
            {
                messagesHandler.Add("danger", ex.Message);
            }

            return(RedirectToAction("index"));
        }
コード例 #3
0
        /// <summary>
        /// List of users
        /// </summary>
        /// <returns>View</returns>
        public IActionResult Index()
        {
            if (sessions.Exist("UserId"))
            {
                List <User> users;

                try
                {
                    users = ticketApi.GetUsers();
                }
                catch (Exception ex)
                {
                    messagesHandler.Add("danger", ex.Message);
                    users = new List <User>();
                }

                ViewBag.Users = users;

                return(View());
            }

            messagesHandler.Add("warning", "You need to be login, to see all users");

            return(RedirectToAction("Index", "Home"));
        }