Example #1
0
        // Displays all ticket agents.
        public void displayAllAgents()
        {
            // Initialise these for later use.
            SubMenus subMenu = new SubMenus();

            JSON         json      = new JSON();
            List <Agent> agentData = json.readTicketAgentData();


            Console.Clear();

            // If no ticket agents exist.
            if ((agentData != null) && (!agentData.Any()))
            {
                Console.Write("No ticket agents exist." +
                              "\nPress any key to return to the menu");
                Console.ReadKey();

                // Return to employee submenu.
                subMenu.employeeSubMenu();
            }
            else
            {
                Console.Write("Ticket Agents\n" +
                              "_______________________________________________________________________________________________________________________\n" +
                              "{0,-10}" + "{1,-20}" + "{2,-50}" + "{3,-20}" + "{4,-10}\n" +
                              "_______________________________________________________________________________________________________________________\n",
                              "Agent ID", "Business Name", "Address", "Contact Name", "Phone No");

                // Format list of ticket agents for displaying.
                foreach (Agent a in agentData)
                {
                    Console.Write("{0,-10}" + "{1,-20}" + "{2,-50}" + "{3,-20}" + "{4,-10}\n" +
                                  "_______________________________________________________________________________________________________________________\n",
                                  a.agentID, a.companyName, a.companyAddress, a.contactName, a.contactPhone);
                }


                Console.Write("\nPress any key to return to the menu.");

                Console.ReadKey();

                // Return to employee submenu.
                subMenu.employeeSubMenu();
            }
        }
Example #2
0
        public void checkBookingFlightStatus()
        {
            // Intitialise for later use.
            SubMenus subMenu = new SubMenus();

            JSON           json        = new JSON();
            List <Booking> bookingData = json.readBookingData();
            List <Flight>  flightData  = json.readFlightData();


            Console.Clear();

            bool intTestLoop = true;

            // Test input for booking ID is correct type.
            while (intTestLoop)
            {
                Console.Write("Please enter the booking reference no:");

                // If the input is an int.
                if (int.TryParse(Console.ReadLine(), out int bookingIDTest))
                {
                    // If booking ID does not exist in booking list (i.e. incorrect id entered).
                    if (!bookingData.Any(b => b.bookingID == bookingIDTest))
                    {
                        Console.Write("\nBooking ID is incorrect, please try again.\n\n");
                    }
                    else
                    {
                        intTestLoop = false;
                        bookingID   = bookingIDTest;
                    }
                }
                // If the input is NOT an int.
                else
                {
                    Console.Write("\nIncorrect input. Please try again.\n\n");
                }
            }

            // Cycle through the booking where the booking ID matches the one entered by the user.
            foreach (Booking b in bookingData.Where(b => b.bookingID == bookingID))
            {
                flightID      = b.flightID;
                customerName  = b.customerName;
                bookingStatus = b.bookingStatus;
            }

            foreach (Flight f in flightData.Where(f => f.flightID.ToLower() == flightID.ToLower()))
            {
                flightFrom     = f.flightFrom;
                flightTo       = f.flightTo;
                flightDateTime = f.flightDateTime;
            }

            // Temporary variable to hold result of converting bookingStatus to something meaningful to user.
            string status;

            // Convert bookingStatus into something meaningful to user.
            if (bookingStatus)
            {
                status = "Confirmed";
            }
            else
            {
                status = "Not Confirmed";
            }

            Console.Write("\n\nYour Booking Details" +
                          "\n========================================" +
                          "\nReference:\t{0}" +
                          "\nStatus:\t\t{1}" +
                          "\nName:\t\t{2}" +
                          "\nFlight No:\t{3}" +
                          "\nFlight From:\t{4}" +
                          "\nFlight To:\t{5}" +
                          "\nDate:\t\t{6:dd/MM/yyyy}" +
                          "\n\nPress any key to return to the menu.",
                          bookingID, status, customerName, flightID, flightFrom, flightTo, flightDateTime);

            Console.ReadKey();

            // Return to customer submenu.
            subMenu.customerSubMenu();
        }
Example #3
0
        // Displays the main menu options.
        public void initMenu()
        {
            bool exitMenuLoop = false;

            while (!exitMenuLoop)
            {
                Console.Clear();

                Console.Write("Welcome to Around-The-World\n" +
                              "================================================\n" +
                              "\t1. Airline Employee\n\n" +
                              "\t2. Ticket Agent\n\n" +
                              "\t3. Customer\n\n" +
                              "\t4. Quit\n\n" +
                              "Enter an option:");

                string menuSelectString = Console.ReadLine();
                int    menuSelectInt;
                bool   menuSelectTest = int.TryParse(menuSelectString, out menuSelectInt);

                // If the input is an int
                if (menuSelectTest)
                {
                    // If the option selected is an int, between 1-4 (inclusive).
                    if (menuSelectInt > 0 & menuSelectInt < 5)
                    {
                        switch (menuSelectInt)
                        {
                        case 1:
                        {
                            // Display employee submenu.
                            exitMenuLoop = true;
                            SubMenus subMenu = new SubMenus();
                            subMenu.employeeSubMenu();
                            break;
                        }

                        case 2:
                        {
                            // Display flight centre (agent) submenu.
                            exitMenuLoop = true;
                            SubMenus subMenu = new SubMenus();
                            subMenu.agentSubMenu();
                            break;
                        }

                        case 3:
                        {
                            // Display customer submenu.
                            exitMenuLoop = true;
                            SubMenus subMenu = new SubMenus();
                            subMenu.customerSubMenu();
                            break;
                        }

                        case 4:
                        {
                            Environment.Exit(0);
                            break;
                        }
                        }
                    }
                    // If the option selected is an int, but NOT between 1-4 (inclusive).
                    else
                    {
                        Console.WriteLine("\nIncorrect input. The number has to be between 1 and 4." +
                                          "\nPress any key to try again.");
                        Console.ReadKey();
                    }
                }
                // If the option selected is NOT an int.
                else
                {
                    Console.Write("\nIncorrect input. Please enter a whole number between 1 and 4." +
                                  "\nPress any key to try again.");
                    Console.ReadKey();
                }
            }
        }
        // Adds a new booking for a specific flight.
        public void addBooking()
        {
            // Intitialise for later use.
            SubMenus subMenu = new SubMenus();
            JSON     json    = new JSON();

            List <Flight>  flightData  = json.readFlightData();
            List <Booking> bookingData = json.readBookingData();


            Console.Clear();

            Console.Write("Enter the flight ID to book ticket:");
            flightID = Console.ReadLine();



            // If flight ID exists in flight schedules.
            if (flightData.Exists(f => f.flightID.ToLower() == flightID.ToLower()))
            {
                // If no bookings exist in bookings.json file.
                if ((bookingData != null) && (!bookingData.Any()))
                {
                    flightAvailability = true;
                }

                // If bookings exist in bookings.json file.
                else
                {
                    foreach (Booking b in bookingData)
                    {
                        // Count the total number of tickets already booked for the specific flightID.
                        if (b.flightID.ToLower() == flightID.ToLower())
                        {
                            totalBookings += b.numberOfTickets;
                        }
                        // If flight ID is NOT found in any bookings.
                        else
                        {
                            flightAvailability = true;
                        }
                    }

                    // Check if the selected flight is fully booked.
                    foreach (Flight f in flightData)
                    {
                        if (f.flightID.ToLower() == flightID.ToLower())
                        {
                            // If seats are still available for the selected flight.
                            if (totalBookings < f.capacity)
                            {
                                flightAvailability = true;
                            }
                            // If all seats for the selected flight are already booked.
                            else
                            {
                                flightAvailability = false;
                            }
                        }
                    }
                }

                // If flight is available for booking.
                if (flightAvailability)
                {
                    Console.Write("Bookings are available for this flight.\n" +
                                  "Please enter the following details...\n");

                    Console.Write("\nName of ticket agency:");

                    ticketAgent = Console.ReadLine();

                    Console.Write("\nCustomer's name:");

                    customerName = Console.ReadLine();

                    Console.Write("\nCustomer's phone number:");

                    customerPhone = Console.ReadLine();

                    bool intTestLoop = true;

                    foreach (Flight f in flightData)
                    {
                        if (f.flightID.ToLower() == flightID.ToLower())
                        {
                            // Test input to check if numberOfTickets is correct type.
                            while (intTestLoop)
                            {
                                Console.Write("\nHow many tickets are being booked:");

                                // If the input is an int.
                                if (int.TryParse(Console.ReadLine(), out int numberOfTicketsTest))
                                {
                                    // If the booking doesn't exceed the maximum capacity of the flight AND is greater than 0
                                    if ((numberOfTicketsTest <= (f.capacity - totalBookings)) && (numberOfTicketsTest > 0))
                                    {
                                        intTestLoop     = false;
                                        numberOfTickets = numberOfTicketsTest;
                                    }
                                    else
                                    {
                                        Console.Write("Invalid amount. Number of tickets exceeds the capacity of the flight.");
                                    }
                                }
                                // If the input is NOT an int.
                                else
                                {
                                    Console.Write("Incorrect input. Please enter a whole number.");
                                }
                            }

                            // Calculate the cost of the booking.
                            bookingPrice = numberOfTickets * f.ticketPrice;
                        }
                    }

                    // Base the booking ID on the number of entries in the bookings.json file.
                    bookingID = bookingData.Count + 1;


                    bookingData.Add(new Booking
                    {
                        flightID        = flightID,
                        bookingID       = bookingID,
                        customerName    = customerName,
                        customerPhone   = customerPhone,
                        numberOfTickets = numberOfTickets,
                        bookingPrice    = bookingPrice,
                        ticketAgent     = ticketAgent,
                        // False means 'not confirmed'.
                        bookingStatus = false
                    });

                    json.saveBookingData(bookingData);


                    Console.Write("\n\nYour booking ID is {0}." +
                                  "\nPress any key to return to the menu.", bookingID);
                    Console.ReadKey();

                    // Return to flight centre submenu.
                    subMenu.agentSubMenu();
                }
                // If flight is NOT available for booking.
                else
                {
                    Console.Write("\nNo bookings are able to be made for this flight.\n" +
                                  "Press any key to return to the menu.");
                    Console.ReadKey();

                    // Return to flight centre submenu.
                    subMenu.agentSubMenu();
                }
            }
            // If flight ID DOESN'T exist in flight schedules.
            else
            {
                Console.Write("\nNo flights exist with that flight ID.\n" +
                              "Press any key to return to the menu.");
                Console.ReadKey();

                // Return to flight centre submenu.
                subMenu.agentSubMenu();
            }
        }
        // Checks booking status for a specific booking.
        public void checkBookingStatus()
        {
            // Intitialise for later use.
            SubMenus subMenu = new SubMenus();

            JSON           json        = new JSON();
            List <Booking> bookingData = json.readBookingData();


            Console.Clear();

            bool intTestLoop = true;

            // Test input for booking ID is correct type.
            while (intTestLoop)
            {
                Console.Write("Please enter the booking reference no:");

                // If the input is an int.
                if (int.TryParse(Console.ReadLine(), out int bookingIDTest))
                {
                    // If booking ID does not exist in booking list (i.e. incorrect id entered).
                    if (!bookingData.Any(b => b.bookingID == bookingIDTest))
                    {
                        Console.Write("\nBooking ID is incorrect, please try again.");
                    }
                    else
                    {
                        intTestLoop = false;
                        bookingID   = bookingIDTest;
                    }
                }
                // If the input is NOT an int.
                else
                {
                    Console.Write("\nIncorrect input. Please try again.");
                }
            }

            // Cycle through the booking where the booking ID matches the one entered by the user.
            foreach (Booking b in bookingData.Where(b => b.bookingID == bookingID))
            {
                if (b.bookingStatus)
                {
                    Console.Write("\nYour booking status for {0} with ID {1} is confirmed." +
                                  "\nPress any key to return to the menu.", b.customerName, b.bookingID);
                    Console.ReadKey();

                    // Return to flight centre submenu.
                    subMenu.agentSubMenu();
                }
                else
                {
                    Console.Write("\nYour booking status for {0} with ID {1} is not confirmed." +
                                  "\nPress any key to return to the menu.", b.customerName, b.bookingID);
                    Console.ReadKey();

                    // Return to flight centre submenu.
                    subMenu.agentSubMenu();
                }
            }
        }
        // Searches for flights that match combination of origin and destination.
        public void searchFlight()
        {
            // Intitialise for later use.
            SubMenus subMenu = new SubMenus();

            JSON          json       = new JSON();
            List <Flight> flightData = json.readFlightData();


            Console.Clear();

            // If no flight schedules exist.
            if ((flightData != null) && (!flightData.Any()))
            {
                Console.Write("No flight schedules exist." +
                              "\n\nPress any key to return to the menu");
                Console.ReadKey();

                // Return to flight centre submenu.
                subMenu.agentSubMenu();
            }
            else
            {
                // Prompt for user input.
                Console.Write("Search For Flight\n" +
                              "=============================================\n\n" +
                              "Flight from:");

                flightFrom = Console.ReadLine();

                Console.Write("\nFlight to:");

                flightTo = Console.ReadLine();


                // Create temporary list to hold search results.
                List <Flight> searchResults = new List <Flight>();

                foreach (Flight f in flightData)
                {
                    if ((flightFrom.ToLower() == f.flightFrom.ToLower()) && (flightTo.ToLower() == f.flightTo.ToLower()))
                    {
                        {
                            searchResults.Add(f);
                        }
                    }
                }

                // If the search finds matching results.
                if (searchResults.Count > 0)
                {
                    Console.Write("\n____________________________________________________________________________________________________________________\n" +
                                  "{0,-10}" + "{1,-15}" + "{2,-30}" + "{3,-15}" + "{4,-10}\n" +
                                  "____________________________________________________________________________________________________________________\n",
                                  "ID", "Flight Type", "Flight Details", "Date", "Time");

                    foreach (Flight f in searchResults)
                    {
                        Console.Write("{0,-10}" + "{1,-15}" + "{2,-30}" + "{3,-15:dd/MM/yyyy}" + "{4,-10:HH:mm}\n" +
                                      "____________________________________________________________________________________________________________________\n",
                                      f.flightID, f.flightType, f.flightFrom + " - " + f.flightTo, f.flightDateTime, f.flightDateTime);
                    }
                }
                // If NO matches are found.
                else
                {
                    Console.Write("\nNo flights match your search.");
                }

                Console.Write("\n\nPress any key to return to the menu.");

                Console.ReadKey();

                // Return to flight centre submenu.
                subMenu.agentSubMenu();
            }
        }
        // Displays all FUTURE flights and allows the user to make a booking for a specific future flight.
        public void displayScheduledFlightsAgent()
        {
            // Initialise these for later use.
            SubMenus subMenu = new SubMenus();

            JSON           json        = new JSON();
            List <Flight>  flightData  = json.readFlightData();
            List <Booking> bookingData = json.readBookingData();


            Console.Clear();

            // If no flight schedules exist.
            if ((flightData != null) && (!flightData.Any()))
            {
                Console.Write("No flight schedules exist." +
                              "\n\nPress any key to return to the menu");
                Console.ReadKey();

                // Return to flight centre submenu.
                subMenu.agentSubMenu();
            }

            else
            {
                // Create temporary list to hold future flights data.
                List <Flight> tempFlightData = new List <Flight>();

                foreach (Flight f in flightData)
                {
                    // Check if time of flight is later than current time.
                    if (DateTime.Compare(DateTime.Now, f.flightDateTime) < 0)
                    {
                        tempFlightData.Add(f);
                    }
                }

                // If there are FUTURE flights.
                if (tempFlightData.Count > 0)
                {
                    Console.Write("Flights\n" +
                                  "_______________________________________________________________________________________________________________________\n" +
                                  "{0,-10}" + "{1,-15}" + "{2,-30}" + "{3,-12}" + "{4,-10}" + "{5,-12}" + "{6,-10}\n" +
                                  "_______________________________________________________________________________________________________________________\n",
                                  "ID", "Flight Type", "Flight Details", "Date", "Time", "Price ($)", "Availability");


                    // If no bookings exist in bookings.json file.
                    if ((bookingData != null) && (!bookingData.Any()))
                    {
                        foreach (Flight f in tempFlightData)
                        {
                            totalBookings      = 0;
                            flightAvailability = true;

                            // Format list of flight schedules for displaying.
                            Console.Write("{0,-10}" + "{1,-15}" + "{2,-30}" + "{3,-12:dd/MM/yyyy}" + "{4,-10:HH:mm}" + "{5,-10}" + "{6,-10}" + "{7,-10}" + "{8,-10}\n" +
                                          "_______________________________________________________________________________________________________________________\n",
                                          f.flightID, f.flightType, f.flightFrom + " - " + f.flightTo, f.flightDateTime, f.flightDateTime, f.ticketPrice, f.capacity, totalBookings, flightAvailability);
                        }
                    }

                    // If bookings exist in bookings.json file.
                    else
                    {
                        foreach (Flight f in tempFlightData)
                        {
                            foreach (Booking b in bookingData)
                            {
                                // Count the total number of tickets already booked for the specific flightID.
                                totalBookings = bookingData.Where(x => x.flightID.ToLower() == f.flightID.ToLower()).Sum(x => x.numberOfTickets);
                                // If flight ID is NOT found in any bookings (i.e. bookings = 0)
                                if (totalBookings == 0)
                                {
                                    flightAvailability = true;
                                }
                            }

                            // If seats are still available for the selected flight.
                            if (totalBookings < f.capacity)
                            {
                                flightAvailability = true;
                            }
                            // If all seats for the selected flight are already booked.
                            else
                            {
                                flightAvailability = false;
                            }

                            // Format list of flight schedules for displaying.
                            Console.Write("{0,-10}" + "{1,-15}" + "{2,-30}" + "{3,-12:dd/MM/yyyy}" + "{4,-10:HH:mm}" + "{5,-12}" + "{6,-10}\n" +
                                          "_______________________________________________________________________________________________________________________\n",
                                          f.flightID, f.flightType, f.flightFrom + " - " + f.flightTo, f.flightDateTime, f.flightDateTime, f.ticketPrice, flightAvailability);
                        }
                    }

                    Console.Write("\nEnter the flight ID to book ticket:");
                    flightID = Console.ReadLine();


                    // If flight ID exists in temporary list of flight schedules.
                    if (tempFlightData.Exists(f => f.flightID.ToLower() == flightID.ToLower()))
                    {
                        // If no bookings exist in bookings.json file.
                        if ((bookingData != null) && (!bookingData.Any()))
                        {
                            flightAvailability = true;
                        }

                        // If bookings exist in bookings.json file.
                        else
                        {
                            foreach (Booking b in bookingData)
                            {
                                // Count the total number of tickets already booked for the specific flightID.
                                totalBookings = bookingData.Where(x => x.flightID == flightID).Sum(x => x.numberOfTickets);
                                // If flight ID is NOT found in any bookings (i.e. bookings = 0)
                                if (totalBookings == 0)
                                {
                                    flightAvailability = true;
                                }
                            }

                            // Check if the selected flight is fully booked.
                            foreach (Flight f in flightData)
                            {
                                if (f.flightID.ToLower() == flightID.ToLower())
                                {
                                    // If seats are still available for the selected flight.
                                    if (totalBookings < f.capacity)
                                    {
                                        flightAvailability = true;
                                    }
                                    // If all seats for the selected flight are already booked.
                                    else
                                    {
                                        flightAvailability = false;
                                    }
                                }
                            }
                        }

                        // If flight is available for booking.
                        if (flightAvailability)
                        {
                            Console.Write("\nBookings are available for this flight.\n" +
                                          "Please enter the following details...\n");

                            Console.Write("\nName of ticket agency:");

                            ticketAgent = Console.ReadLine();

                            Console.Write("\nCustomer's name:");

                            customerName = Console.ReadLine();

                            Console.Write("\nCustomer's phone number:");

                            customerPhone = Console.ReadLine();

                            bool intTestLoop = true;

                            foreach (Flight f in tempFlightData)
                            {
                                if (f.flightID.ToLower() == flightID.ToLower())
                                {
                                    // Test input to check if numberOfTickets is correct type.
                                    while (intTestLoop)
                                    {
                                        Console.Write("\nHow many tickets are being booked:");

                                        // If the input is an int.
                                        if (int.TryParse(Console.ReadLine(), out int numberOfTicketsTest))
                                        {
                                            // If the booking doesn't exceed the maximum capacity of the flight AND is greater than 0
                                            if ((numberOfTicketsTest <= (f.capacity - totalBookings)) && (numberOfTicketsTest > 0))
                                            {
                                                intTestLoop     = false;
                                                numberOfTickets = numberOfTicketsTest;
                                            }
                                            else
                                            {
                                                Console.Write("Invalid amount. Number of tickets exceeds the capacity of the flight.");
                                            }
                                        }
                                        // If the input is NOT an int.
                                        else
                                        {
                                            Console.Write("Incorrect input. Please enter a whole number.");
                                        }
                                    }

                                    // Calculate the cost of the booking.
                                    bookingPrice = numberOfTickets * f.ticketPrice;
                                }
                            }

                            // Base the booking ID on the number of entries in the bookings.json file.
                            bookingID = bookingData.Count + 1;

                            bookingData.Add(new Booking
                            {
                                flightID        = flightID,
                                bookingID       = bookingID,
                                customerName    = customerName,
                                customerPhone   = customerPhone,
                                numberOfTickets = numberOfTickets,
                                bookingPrice    = bookingPrice,
                                ticketAgent     = ticketAgent,
                                bookingStatus   = false // False means 'not confirmed'.
                            });

                            json.saveBookingData(bookingData);


                            Console.Write("\n\nYour booking ID is {0}." +
                                          "\nPress any key to return to the menu.", bookingID);
                            Console.ReadKey();

                            // Return to flight centre submenu.
                            subMenu.agentSubMenu();
                        }
                        // If flight is NOT available for booking.
                        else
                        {
                            Console.Write("\nNo bookings are able to be made for this flight.\n" +
                                          "Press any key to return to the menu.");
                            Console.ReadKey();

                            // Return to flight centre submenu.
                            subMenu.agentSubMenu();
                        }
                    }
                    // If flight ID DOESN'T exist in flight schedules.
                    else
                    {
                        Console.Write("\nNo flights exist with that flight ID.\n" +
                                      "Press any key to return to the menu.");
                        Console.ReadKey();

                        // Return to flight centre submenu.
                        subMenu.agentSubMenu();
                    }
                }
                // If there are NO FUTURE flights.
                else
                {
                    Console.Write("There are no upcoming scheduled flights.");
                }

                Console.Write("\nPress any key to return to the menu.");

                Console.ReadKey();

                // Return to flight centre submenu.
                subMenu.agentSubMenu();
            }
        }
Example #8
0
        // Adds new ticket agent.
        public void addTicketAgent()
        {
            // Initialise these for later use.
            SubMenus subMenu = new SubMenus();

            JSON         json      = new JSON();
            List <Agent> agentData = json.readTicketAgentData();


            Console.Clear();

            Console.Write("Add New Ticket Agent\n" +
                          "=============================================\n\n" +
                          "Enter the company name:");

            companyName = Console.ReadLine();

            Console.Write("\nEnter the business address:");
            companyAddress = Console.ReadLine();

            Console.Write("\nContact person name:");
            contactName = Console.ReadLine();

            Console.Write("\nContact person phone:");
            contactPhone = Console.ReadLine();

            // If no ticket agents exist.
            if ((agentData != null) && (!agentData.Any()))
            {
                agentData.Add(new Agent
                {
                    agentID        = 1,
                    companyName    = companyName,
                    companyAddress = companyAddress,
                    contactName    = contactName,
                    contactPhone   = contactPhone,
                });

                json.saveTicketAgentData(agentData);
            }
            else
            {
                // Test if ticket agent already exists.
                foreach (Agent a in agentData)
                {
                    if ((a.companyName.ToLower() == companyName.ToLower()) && (a.companyAddress.ToLower() == companyAddress.ToLower()) &&
                        (a.contactName.ToLower() == contactName.ToLower()) && (a.contactPhone.ToLower() == contactPhone.ToLower()))
                    {
                        Console.Write("\nDetails already exist for this agent.\n" +
                                      "Press any key to try again.");
                        Console.ReadKey();

                        // Return to employee submenu.
                        subMenu.employeeSubMenu();
                    }
                }

                int newAgentID = agentData.Count() + 1;

                // If ticket agent doesn't already exist.
                agentData.Add(new Agent
                {
                    agentID        = newAgentID,
                    companyName    = companyName,
                    companyAddress = companyAddress,
                    contactName    = contactName,
                    contactPhone   = contactPhone,
                });

                json.saveTicketAgentData(agentData);
            }

            Console.Write("\nThe new agent ID is {0}" +
                          "\n\nPress any key to return to the menu.", agentData.Count());

            Console.ReadKey();

            // Return to employee submenu.
            subMenu.employeeSubMenu();
        }
Example #9
0
        //  Displays all ticket bookings for a selected flight.
        public void displayAllBookings()
        {
            // Initialise these for later use.
            SubMenus subMenu = new SubMenus();

            JSON           json        = new JSON();
            List <Flight>  flightData  = json.readFlightData();
            List <Booking> bookingData = json.readBookingData();


            Console.Clear();

            // If no flight schedules exist.
            if ((flightData != null) && (!flightData.Any()))
            {
                Console.Write("No flight schedules exist." +
                              "\nPress any key to return to the menu");
                Console.ReadKey();

                // Return to employee submenu.
                subMenu.employeeSubMenu();
            }
            else
            {
                // If no bookings exist in bookings.json file.
                if ((bookingData != null) && (!bookingData.Any()))
                {
                    Console.Write("No bookings exist for any flights." +
                                  "\n\nPress any key to return to the menu.");

                    Console.ReadKey();

                    // Return to employee submenu.
                    subMenu.employeeSubMenu();
                }

                // If bookings exist in bookings.json file.
                else
                {
                    Console.Write("Flights\n" +
                                  "_______________________________________________________________________________________________________________________\n" +
                                  "{0,-10}" + "{1,-15}" + "{2,-30}" + "{3,-12}" + "{4,-10}" + "{5,-10}" + "{6,-10}" + "{7,-10}" + "{8,-10}\n" +
                                  "_______________________________________________________________________________________________________________________\n",
                                  "ID", "Flight Type", "Flight Details", "Date", "Time", "Price ($)", "Capacity", "Booked", "Availability");

                    foreach (Flight f in flightData)
                    {
                        foreach (Booking b in bookingData)
                        {
                            // Count the total number of tickets already booked for the specific flightID.
                            totalBookings = bookingData.Where(x => x.flightID.ToLower() == f.flightID.ToLower()).Sum(x => x.numberOfTickets);
                            // If flight ID is NOT found in any bookings (i.e. bookings = 0)
                            if (totalBookings == 0)
                            {
                                flightAvailability = true;
                            }
                        }

                        // If seats are still available for the selected flight.
                        if (totalBookings < f.capacity)
                        {
                            flightAvailability = true;
                        }
                        // If all seats for the selected flight are already booked.
                        else
                        {
                            flightAvailability = false;
                        }

                        // Format list of flight schedules for displaying.
                        Console.Write("{0,-10}" + "{1,-15}" + "{2,-30}" + "{3,-12:dd/MM/yyyy}" + "{4,-10:HH:mm}" + "{5,-10}" + "{6,-10}" + "{7,-10}" + "{8,-10}\n" +
                                      "_______________________________________________________________________________________________________________________\n",
                                      f.flightID, f.flightType, f.flightFrom + " - " + f.flightTo, f.flightDateTime, f.flightDateTime, f.ticketPrice, f.capacity, totalBookings, flightAvailability);
                    }
                }

                bool flightIDTestLoop = true;

                while (flightIDTestLoop)
                {
                    Console.Write("\nEnter the flight ID:");

                    flightID = Console.ReadLine();

                    // If flight ID doesn't exist (i.e. incorrectly entered).
                    if (!flightData.Any(f => f.flightID.ToLower() == flightID.ToLower()))
                    {
                        Console.Write("Incorrect flight ID. Please try again.");
                    }
                    else
                    {
                        // If no bookings exist for the selected flight.
                        if (!bookingData.Any(b => b.flightID.ToLower() == flightID.ToLower()))
                        {
                            Console.Write("\nNo bookings exist for the selected flight." +
                                          "\n\nPress any key to return to the menu.");

                            Console.ReadKey();

                            // Return to employee submenu.
                            subMenu.employeeSubMenu();
                        }
                        else
                        {
                            // Create temporary list to hold booking data results for specific flight.
                            List <Booking> tempBookingData = new List <Booking>();
                            flightIDTestLoop = false;

                            // Retrieve list of all bookings with status(boolean) as confirmed (true) or not confirmed (false).
                            foreach (Booking b in bookingData)
                            {
                                if (b.flightID.ToLower() == flightID.ToLower())
                                {
                                    tempBookingData.Add(b);
                                }
                            }


                            Console.Write("\n\nTicket Bookings for flight {0}\n" +
                                          "_______________________________________________________________________________________________________________________\n" +
                                          "{1,-20}" + "{2,-20}" + "{3,-20}" + "{4,-27}" + "{5,-15}" + "{6,-10}\n" +
                                          "_______________________________________________________________________________________________________________________\n",
                                          flightID, "Booking ID", "Name", "No. of Tickets", "Ticket Agent", "Price", "Status");


                            // Format list of bookings for displaying.
                            foreach (Booking b in tempBookingData)
                            {
                                // Temporary variable to hold result of converting bookingStatus to something meaningful to user.
                                string status;

                                // Convert bookingStatus into something meaningful to user.
                                if (b.bookingStatus)
                                {
                                    status = "Confirmed";
                                }
                                else
                                {
                                    status = "Not Confirmed";
                                }

                                Console.Write("{0,-20}" + "{1,-20}" + "{2,-20}" + "{3,-27}" + "${4,-14}" + "{5,-10}\n" +
                                              "_______________________________________________________________________________________________________________________\n",
                                              b.bookingID, b.customerName, b.numberOfTickets, b.ticketAgent, b.bookingPrice, status);
                            }

                            bool intTestLoop = true;

                            while (intTestLoop)
                            {
                                Console.Write("\nEnter the booking ID:");

                                // If the input is an int.
                                if (int.TryParse(Console.ReadLine(), out int bookingIDTest))
                                {
                                    // If booking ID does not exist in temporary booking list (i.e. incorrect id entered).
                                    if (!tempBookingData.Any(b => b.bookingID == bookingIDTest))
                                    {
                                        Console.Write("\nBooking ID is incorrect, please try again.");
                                    }
                                    else
                                    {
                                        intTestLoop = false;

                                        // If booking is already confirmed.
                                        foreach (Booking b in tempBookingData.Where(b => b.bookingID == bookingIDTest))
                                        {
                                            if (b.bookingStatus)
                                            {
                                                Console.Write("\nBooking is already confirmed." +
                                                              "\nPress any key to return to the menu");
                                                Console.ReadKey();

                                                // Return to employee submenu.
                                                subMenu.employeeSubMenu();
                                            }
                                            else
                                            {
                                                b.bookingStatus = true;

                                                // Return change in status back to original booking list.
                                                foreach (Booking c in bookingData.Where(c => c.bookingID == bookingIDTest))
                                                {
                                                    c.bookingStatus = b.bookingStatus;
                                                    json.saveBookingData(bookingData);
                                                }

                                                Console.Write("\nBooking is confirmed." +
                                                              "\nPress any key to return to the menu.");
                                                Console.ReadKey();

                                                // Return to employee submenu.
                                                subMenu.employeeSubMenu();
                                            }
                                        }
                                    }
                                }
                                // If the input is NOT an int.
                                else
                                {
                                    Console.Write("\nBooking ID is incorrect, please try again.");
                                }
                            }
                        }
                    }
                }
            }
        }
Example #10
0
        // Displays all scheduled flights.
        public void displayScheduledFlights()
        {
            // Initialise these for later use.
            SubMenus subMenu = new SubMenus();

            JSON           json        = new JSON();
            List <Flight>  flightData  = json.readFlightData();
            List <Booking> bookingData = json.readBookingData();


            Console.Clear();

            // If no flight schedules exist.
            if ((flightData != null) && (!flightData.Any()))
            {
                Console.Write("No flight schedules exist." +
                              "\nPress any key to return to the menu");
                Console.ReadKey();

                // Return to employee submenu.
                subMenu.employeeSubMenu();
            }
            else
            {
                Console.Write("Flights\n" +
                              "_______________________________________________________________________________________________________________________\n" +
                              "{0,-10}" + "{1,-15}" + "{2,-30}" + "{3,-12}" + "{4,-10}" + "{5,-10}" + "{6,-10}" + "{7,-10}" + "{8,-10}\n" +
                              "_______________________________________________________________________________________________________________________\n",
                              "ID", "Flight Type", "Flight Details", "Date", "Time", "Price ($)", "Capacity", "Booked", "Availability");


                // If no bookings exist in bookings.json file.
                if ((bookingData != null) && (!bookingData.Any()))
                {
                    foreach (Flight f in flightData)
                    {
                        totalBookings      = 0;
                        flightAvailability = true;

                        // Format list of flight schedules for displaying.
                        Console.Write("{0,-10}" + "{1,-15}" + "{2,-30}" + "{3,-12:dd/MM/yyyy}" + "{4,-10:HH:mm}" + "{5,-10}" + "{6,-10}" + "{7,-10}" + "{8,-10}\n" +
                                      "_______________________________________________________________________________________________________________________\n",
                                      f.flightID, f.flightType, f.flightFrom + " - " + f.flightTo, f.flightDateTime, f.flightDateTime, f.ticketPrice, f.capacity, totalBookings, flightAvailability);
                    }
                }

                // If bookings exist in bookings.json file.
                else
                {
                    foreach (Flight f in flightData)
                    {
                        foreach (Booking b in bookingData)
                        {
                            // Count the total number of tickets already booked for the specific flightID.
                            totalBookings = bookingData.Where(x => x.flightID.ToLower() == f.flightID.ToLower()).Sum(x => x.numberOfTickets);
                            // If flight ID is NOT found in any bookings (i.e. bookings = 0)
                            if (totalBookings == 0)
                            {
                                flightAvailability = true;
                            }
                        }

                        // If seats are still available for the selected flight.
                        if (totalBookings < f.capacity)
                        {
                            flightAvailability = true;
                        }
                        // If all seats for the selected flight are already booked.
                        else
                        {
                            flightAvailability = false;
                        }

                        // Format list of flight schedules for displaying.
                        Console.Write("{0,-10}" + "{1,-15}" + "{2,-30}" + "{3,-12:dd/MM/yyyy}" + "{4,-10:HH:mm}" + "{5,-10}" + "{6,-10}" + "{7,-10}" + "{8,-10}\n" +
                                      "_______________________________________________________________________________________________________________________\n",
                                      f.flightID, f.flightType, f.flightFrom + " - " + f.flightTo, f.flightDateTime, f.flightDateTime, f.ticketPrice, f.capacity, totalBookings, flightAvailability);
                    }
                }

                Console.Write("\nPress any key to return to the menu.");

                Console.ReadKey();

                // Return to employee submenu.
                subMenu.employeeSubMenu();
            }
        }
Example #11
0
        // Adds new flight schedule.
        public void addFlightSchedule()
        {
            // Initialise these for later use.
            SubMenus subMenu = new SubMenus();

            JSON          json       = new JSON();
            List <Flight> flightData = json.readFlightData();


            Console.Clear();

            Console.Write("Add New Flight Schedule\n" +
                          "=============================================\n\n" +
                          "Enter the flight ID:");

            flightID = Console.ReadLine();

            Console.Write("\nEnter the flight type:");
            flightType = Console.ReadLine();

            Console.Write("\nFlight from:");
            flightFrom = Console.ReadLine();

            Console.Write("\nFlight to:");
            flightTo = Console.ReadLine();


            bool dateTimeTestLoop = true;

            // Test input for date and time is correct type.
            while (dateTimeTestLoop)
            {
                Console.Write("\nDate of flight (dd/mm/yyyy):");
                string flightDate = Console.ReadLine();

                Console.Write("\nTime of flight (24hr time - hh:mm):");
                string flightTime = Console.ReadLine();

                if (DateTime.TryParse(flightDate + " " + flightTime, out DateTime dateTimeTest))
                {
                    dateTimeTestLoop = false;
                    flightDateTime   = dateTimeTest;
                }
                else
                {
                    Console.Write("Incorrect date/time. Please try again.");
                }
            }

            bool floatTestLoop = true;

            // Test input for ticket price is correct type.
            while (floatTestLoop)
            {
                Console.Write("\nTicket Price ($):");

                // If the input is a float.
                if (float.TryParse(Console.ReadLine(), out float ticketPriceTest))
                {
                    floatTestLoop = false;
                    ticketPrice   = ticketPriceTest;
                }
                // If the input is NOT a float.
                else
                {
                    Console.Write("Incorrect input. Please enter a number.");
                }
            }

            bool intTestLoop = true;

            // Test input for capacity is correct type.
            while (intTestLoop)
            {
                Console.Write("\nCapacity:");

                // If the input is an int.
                if (int.TryParse(Console.ReadLine(), out int capacityTest))
                {
                    intTestLoop = false;
                    capacity    = capacityTest;
                }
                // If the input is NOT an int.
                else
                {
                    Console.Write("Incorrect input. Please enter a whole number.");
                }
            }

            // If no flight schedules exist.
            if ((flightData != null) && (!flightData.Any()))
            {
                flightData.Add(new Flight
                {
                    flightID       = flightID,
                    flightType     = flightType,
                    flightFrom     = flightFrom,
                    flightTo       = flightTo,
                    flightDateTime = flightDateTime,
                    ticketPrice    = ticketPrice,
                    capacity       = capacity
                });

                json.saveFlightData(flightData);
            }
            else
            {
                // Test if flight ID already exists.
                foreach (Flight f in flightData)
                {
                    if (f.flightID.ToLower() == flightID.ToLower())
                    {
                        Console.Write("\nDetails already exist for this flight ID.\n" +
                                      "Press any key to try again.");
                        Console.ReadKey();

                        // Return to employee submenu.
                        subMenu.employeeSubMenu();
                    }
                }

                // If flight ID doesn't already exist.
                flightData.Add(new Flight
                {
                    flightID       = flightID,
                    flightType     = flightType,
                    flightFrom     = flightFrom,
                    flightTo       = flightTo,
                    flightDateTime = flightDateTime,
                    ticketPrice    = ticketPrice,
                    capacity       = capacity
                });

                json.saveFlightData(flightData);
            }

            Console.Write("\nFlight schedule has been successfully added.\n\n" +
                          "Press any key to return to the menu.");
            Console.ReadKey();

            // Return to employee submenu.
            subMenu.employeeSubMenu();
        }