Beispiel #1
0
        public bool UserMenu(string username)
        {
            EventsHandler handler = new EventsHandler();

            Console.ForegroundColor = ConsoleColor.Yellow;

            Console.Clear();
            Console.WriteLine("");
            Console.WriteLine("\t\t[+] User Main Menu [+]");
            Console.WriteLine("\tPlease select from one of the following options");
            Console.WriteLine("\t\t      [1, 2, 3]\n");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\t\t1: Book tickets");
            Console.WriteLine("\t\t2: View self purchased tickets");
            Console.WriteLine("\t\t3: Display event list");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("\nType 'logout' to logout of your account\n");

            string option = Console.ReadLine();

            switch (option)
            {
            case "1":
                Console.WriteLine("Option 1 Selected.");
                handler.BookTickets(username);
                return(true);

            case "2":
                Console.WriteLine("Option 2 Selected.");
                handler.ViewOwnTickets(username);
                return(true);

            case "3":
                Console.WriteLine("Option 3 Selected.");
                handler.PrintUserEvents(username);
                return(true);

            case "logout":
            case "exit":
                Console.Clear();
                Login();
                return(true);

            default:
                Console.WriteLine("Invalid option selected.");
                System.Threading.Thread.Sleep(1000);
                UserMenu(username);
                return(true);
            }
        }
Beispiel #2
0
        public bool DeleteEvent(string username)
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Event deletion loaded.");
            System.Threading.Thread.Sleep(1000);
            Console.Clear();
            EventsHandler handler = new EventsHandler();

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Running event deletion process.");

            string filename = "events.json";
            List <EventDetails> EventsList = GetEvents(username);

            Console.WriteLine("Please enter the ID of event you would like to delete: ");
            int          EventID       = int.Parse(Console.ReadLine());
            EventDetails UpdateEvent   = EventsList.Find(EventDetails => EventDetails.EventID == EventID);
            int          UpdateEventID = EventsList.FindIndex(EventDetails => EventDetails.EventID == EventID);

            if (UpdateEvent == null)
            {
                Console.WriteLine("The event specified does not exist, Press any key to continue.");
                Console.ReadKey();
                handler.DeleteEvent(username);
                return(true);
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Current Event Information:");
            Console.WriteLine("Event ID: " + UpdateEvent.EventID);
            Console.WriteLine("Event Name: " + UpdateEvent.EventName);
            Console.WriteLine("Tickets available: " + UpdateEvent.AmountTickets); //+ availabletickets
            Console.WriteLine("Price per ticket: " + UpdateEvent.PricePerTicket); //+ priceperticket
            Console.WriteLine("Date and time: " + UpdateEvent.DateTime);          //+ datetime
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Are you sure you want to delete " + UpdateEvent.EventName);
            if (Console.ReadLine() == "yes")
            {
                EventsList.RemoveAt(UpdateEventID);
                string json = JsonConvert.SerializeObject(EventsList.ToArray(), Formatting.Indented);
                System.IO.File.WriteAllText(filename, json);
                Console.WriteLine("Event " + UpdateEvent.EventName + " has been removed. Press any key to continue.");
                AddLog("[" + username + "] deleted event [" + UpdateEvent.EventName + "]");
                Console.ReadKey();
                manager.MenuChooser(username);
            }

            return(true);
        }
Beispiel #3
0
        public void UpdateEventInfo(string username)
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Updating event information loaded.");
            System.Threading.Thread.Sleep(1000);
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Running event information update process.");
            //TODO create function to load events from json or do it within main
            //TODO add search by name
            EventsHandler handler = new EventsHandler();

            List <EventDetails> EventsList = GetEvents(username);
            int LastInsertID = 0;

            if (EventsList.Count > 0)
            {
                LastInsertID = EventsList[EventsList.Count - 1].EventID;
            }

            Console.WriteLine("Please enter an event ID or Name:");
            EventDetails UpdateEvent;
            int          UpdateEventID;
            string       EventName = Console.ReadLine();
            int          EventID;

            if (int.TryParse(EventName, out EventID))
            {
                UpdateEvent   = EventsList.Find(EventDetails => EventDetails.EventID == EventID);
                UpdateEventID = EventsList.FindIndex(EventDetails => EventDetails.EventID.Equals(EventID));
            }
            else
            {
                UpdateEvent   = EventsList.Find(EventDetails => EventDetails.EventName.Equals(EventName));
                UpdateEventID = EventsList.FindIndex(EventDetails => EventDetails.EventName.Equals(EventName));
            }
            if (UpdateEvent == null)
            {
                Console.WriteLine("The event specified does not exist.");
                handler.UpdateEventInfo(username);
                return;
            }


            //ID IS VALID
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Current Event Information:");
            Console.WriteLine("Event ID: " + UpdateEvent.EventID);
            Console.WriteLine("Event Name: " + UpdateEvent.EventName);
            Console.WriteLine("Tickets available: " + UpdateEvent.AmountTickets);
            Console.WriteLine("Price per ticket: " + UpdateEvent.PricePerTicket);
            Console.WriteLine("Date and time: " + UpdateEvent.DateTime);
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("\nWhich part of the event would you like to update?");
            string etype = Console.ReadLine();


            if (etype.ToLower().Contains("name"))
            {
                Console.WriteLine("\nThe current Event Name is: " + UpdateEvent.EventName);
                Console.WriteLine("Please enter a new event name.");
                UpdateEvent.EventName = Console.ReadLine();
                UpdateEventList(UpdateEventID, UpdateEvent);
                AddLog("[" + username + "] updated [" + UpdateEvent.EventName + "]");
                Console.WriteLine("The event name has been updated. Press any key to continue.");
                Console.ReadKey();
                handler.UpdateEventInfo(username);
                return;
            }
            if (etype.ToLower().Contains("tickets available") || etype.ToLower().Contains("tickets") || etype.ToLower().Contains("ticket") || etype.ToLower().Contains("amount"))
            {
                Console.WriteLine("\nThe current number of tickets available are: " + UpdateEvent.AmountTickets);
                Console.WriteLine("Please enter a new amount of tickets available for this event.");
                UpdateEvent.AmountTickets = Convert.ToInt32(Console.ReadLine());

                //update tickets in JSON file
                UpdateEventList(UpdateEventID, UpdateEvent);
                AddLog("[" + username + "] updated [" + UpdateEvent.EventName + "]");
                Console.WriteLine("Number of tickets has been updated. Press any key to continue.");
                Console.ReadKey();
                handler.UpdateEventInfo(username);
            }

            if (etype.ToLower().Contains("price per ticket") || etype.ToLower().Contains("price") || etype.ToLower().Contains("cost"))
            {
                Console.WriteLine("\nThe current price per ticket is: " + UpdateEvent.PricePerTicket);
                Console.WriteLine("Please enter a new price per ticket for this event.");
                UpdateEvent.PricePerTicket = Convert.ToInt32(Console.ReadLine());

                //update pricepertickets in JSON file
                UpdateEventList(UpdateEventID, UpdateEvent);
                AddLog("[" + username + "] updated [" + UpdateEvent.EventName + "]");
                Console.WriteLine("Price per ticket has been updated. Press any key to continue.");
                Console.ReadKey();
                handler.UpdateEventInfo(username);
            }

            if (etype.ToLower().Contains("date") || etype.ToLower().Contains("time"))
            {
                Console.WriteLine("The current Date and Time of the event is: " + UpdateEvent.DateTime);
                Regex DateReg = new Regex(@"([0-9]{1,2}[/][0-9]{1,2}[/][0-9]{4}[ ][0-2][0-9][:][0-9]{2})");
                Console.WriteLine("Please enter the Date and Time of the event in the format DD/MM/YYYY HH:MM");
                string TempVar = Console.ReadLine();
                while (DateReg.Matches(TempVar).Count == 0)
                {
                    Console.WriteLine("Invalid input given.");
                    Console.WriteLine("Please enter the Date and Time of this event in the format DD/MM/YYYY HH:MM");
                    TempVar = Console.ReadLine();
                }
                UpdateEvent.DateTime = TempVar;
                UpdateEventList(UpdateEventID, UpdateEvent);
                AddLog("[" + username + "] updated [" + UpdateEvent.EventName + "]");
                Console.WriteLine("The number of tickets for this event has been updated. Press any key to continue.");
                Console.ReadKey();
                manager.MenuChooser(username);
            }
            else
            {
                Console.WriteLine("Invalid type specified, retrying event update.");
                System.Threading.Thread.Sleep(2000);
                UpdateEventInfo(username);
            }
        }
Beispiel #4
0
        public bool BookTickets(string username)
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Ticket booking loaded.");
            System.Threading.Thread.Sleep(1000);
            Console.Clear();
            EventsHandler handler = new EventsHandler();


            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Running ticket booking process.");
            List <EventDetails> EventsList = GetEvents(username);
            int LastInsertID = EventsList[EventsList.Count - 1].EventID;

            Console.WriteLine("Please enter an event ID or Name:");
            EventDetails UpdateEvent;
            int          UpdateEventID;

            string EventName = Console.ReadLine();
            int    EventID;

            if (int.TryParse(EventName, out EventID))
            {
                UpdateEvent   = EventsList.Find(EventDetails => EventDetails.EventID == EventID);
                UpdateEventID = EventsList.FindIndex(EventDetails => EventDetails.EventID.Equals(EventID));
            }
            else
            {
                UpdateEvent   = EventsList.Find(EventDetails => EventDetails.EventName.Equals(EventName));
                UpdateEventID = EventsList.FindIndex(EventDetails => EventDetails.EventName.Equals(EventName));
            }
            if (UpdateEvent == null)
            {
                Console.WriteLine("The event specified does not exist, Press any key to continue.");
                Console.ReadKey();
                handler.BookTickets(username);
                return(true);
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("\nCurrent Event Information:");
            Console.WriteLine("Event ID: " + UpdateEvent.EventID);
            Console.WriteLine("Event Name: " + UpdateEvent.EventName);
            Console.WriteLine("Tickets available: " + UpdateEvent.AmountTickets);
            Console.WriteLine("Price per ticket: " + UpdateEvent.PricePerTicket);
            Console.WriteLine("Date and time: " + UpdateEvent.DateTime);
            Console.ForegroundColor = ConsoleColor.Red;
            if (UpdateEvent.AmountTickets > 0)
            {
                Console.WriteLine("Please enter your name:");
                string CustomerName = Console.ReadLine();
                Console.WriteLine("Please enter your address:");
                string CustomerAddress = Console.ReadLine();
                Console.WriteLine("Please enter number of tickets:");
                int NumberTickets = int.Parse(Console.ReadLine());
                while (UpdateEvent.AmountTickets - NumberTickets < 0 || NumberTickets < 1)
                {
                    Console.WriteLine("Invalid Number of tickets!");
                    Console.WriteLine("Please enter number of tickets:");
                    NumberTickets = int.Parse(Console.ReadLine());
                }

                Console.WriteLine("Total cost: £" + UpdateEvent.PricePerTicket * NumberTickets);

                BookingDetails booking = new BookingDetails();
                booking.CustomerName    = CustomerName;
                booking.CustomerAddress = CustomerAddress;
                booking.NumberTickets   = NumberTickets;
                booking.PurchasedBy     = username;

                UpdateEvent.AmountTickets -= NumberTickets;
                UpdateEvent.BookingDetails.Add(booking);

                UpdateEventList(UpdateEventID, UpdateEvent);
                AddLog("[" + CustomerName + "] booked [" + NumberTickets + "] tickets for [£" + UpdateEvent.PricePerTicket * NumberTickets + "]");
                manager.MenuChooser(username);
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("There are no tickets available for this event, Press any key to continue.");
                Console.ReadKey();
                handler.BookTickets(username);
            }
            return(true);
        }
Beispiel #5
0
        public bool AdminMenu(string username)
        {
            EventsHandler handler = new EventsHandler();

            Console.ForegroundColor = ConsoleColor.Yellow;

            Console.Clear();
            Console.WriteLine("");
            Console.WriteLine("\t\t[+] Admin Main Menu [+]");
            Console.WriteLine("\tPlease select from one of the following options");
            Console.WriteLine("\t\t  [1, 2, 3, 4, 5, 6]\n");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\t\t1: Create an event");
            Console.WriteLine("\t\t2: Update an event");
            Console.WriteLine("\t\t3: Delete an event");
            Console.WriteLine("\t\t4: Book tickets");
            Console.WriteLine("\t\t5: Display event list");
            Console.WriteLine("\t\t6: View self purchased tickets");
            Console.WriteLine("\t\t7: Display transaction log");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("\nType 'logout' to logout of your account\n");

            string option = Console.ReadLine();


            switch (option)
            {
            case "1":
                Console.WriteLine("Option 1 Selected.");
                handler.AddEvent(username);
                return(true);

            case "2":
                Console.WriteLine("Option 2 Selected.");
                handler.UpdateEventInfo(username);
                return(true);

            case "3":
                Console.WriteLine("Option 3 Selected.");
                handler.DeleteEvent(username);
                return(true);

            case "4":
                Console.WriteLine("Option 4 Selected.");
                handler.BookTickets(username);
                return(true);

            case "5":
                Console.WriteLine("Option 5 Selected.");
                handler.PrintEvents(username);
                return(true);

            case "6":
                Console.WriteLine("Option 6 Selected.");
                handler.ViewOwnTickets(username);
                return(true);

            case "7":
                Console.WriteLine("Option 7 Selected.");
                handler.DisplayLog(username);
                return(true);

            case "logout":
            case "exit":
                Console.Clear();
                Login();
                return(true);

            default:
                Console.WriteLine("Invalid option selected.");
                System.Threading.Thread.Sleep(1000);
                AdminMenu(username);
                return(true);
            }
        }