コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }