Ejemplo n.º 1
0
        // Takes away the ability for a badge to open a specific door
        private static void RemoveDoorFromBadgeOption()
        {
            int current_key = ChooseBadgeKey();

            Console.WriteLine(divider);

            Console.WriteLine($"Doors unlockable by Badge #{current_key}: ");
            Console.WriteLine($"  {string.Join(", ", BadgeRepository.GetDictionary()[current_key])}");
            Console.WriteLine();

            while (true)
            {
                string to_remove = Input($"Which door# should badge #{current_key} not be able to access? ");

                if (BadgeRepository.GetDictionary()[current_key].Contains(to_remove))
                {
                    BadgeRepository.RemoveValueFromDict(current_key, to_remove);
                    Console.WriteLine($"\nBadge #{current_key} can no longer open door #{to_remove}.");
                    Input("Press enter/return ");
                    return;
                }

                else
                {
                    Console.WriteLine($"\nBadge #{current_key} already can't open that door.");
                    Input("Press enter/return ");
                    Console.WriteLine(divider);
                }
            }
        }
Ejemplo n.º 2
0
        // Grants a badge the ability to open a specific door
        private static void AddDoorToBadgeOption()
        {
            int current_key = ChooseBadgeKey();

            Console.WriteLine(divider);

            while (true)
            {
                string new_door = Input($"What new door# should badge #{current_key} be able to access? ");

                if (BadgeRepository.GetDictionary()[current_key].Contains(new_door))
                {
                    Console.WriteLine($"\nBadge #{current_key} can already open that door.");
                    Input("Press enter/return ");
                    Console.WriteLine(divider);
                }

                else
                {
                    BadgeRepository.AddValueToDict(current_key, new_door);
                    Console.WriteLine($"\nBadge #{current_key} can now open door #{new_door}.");
                    Input("Press enter/return ");
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        // Create a new badge. This badge cannot open any doors until the user chooses to add a door to it.
        private static void CreateBadgeOption()
        {
            int badge_id;

            while (true)
            {
                badge_id = int.Parse(Input("Give an ID# to this badge: "));

                if (BadgeRepository.GetDictionary().ContainsKey(badge_id))
                {
                    Console.WriteLine("\nA badge with that ID already exists.");
                    Input("Press enter/return ");
                    Console.WriteLine(divider);
                }

                else
                {
                    break;
                }
            }

            BadgeRepository.AddNewKeyToDict(badge_id);
            Console.WriteLine("\nYour badge has been created!");
            Input("Press enter/return ");
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            BadgeRepository badgeRepo = new BadgeRepository();
            Dictionary <int, List <string> > badgeDictionary = badgeRepo.GetDictionary();

            string response = null;

            while (response != "4")
            {
                Console.Clear();
                Console.WriteLine($"Hello Security Admin. What would you like to do?" +
                                  $"\n1. Add a badge" +
                                  $"\n2. Edit a badge" +
                                  $"\n3. List all badges" +
                                  $"\n4. Exit");
                response = Console.ReadLine();

                if (response == "1")
                {
                    Console.Clear();
                    List <string> doorList     = new List <string>();
                    string        doorResponse = "y";

                    Console.Write("What is the number on the badge: ");
                    int badgeNum = Int32.Parse(Console.ReadLine());
                    while (doorResponse != "n")
                    {
                        if (doorResponse == "y")
                        {
                            Console.Write("List a door that it needs access to: ");
                            string newDoor = Console.ReadLine();
                            doorList.Add(newDoor);
                            Console.Write("Are there any other doors? (y/n): ");
                            doorResponse = Console.ReadLine();
                        }
                        else
                        {
                            Console.WriteLine("Invalid Input");
                            Console.Write("Are there any other doors? (y/n): ");
                            doorResponse = Console.ReadLine();
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        // Lists all the available badges, asks the user to choose one, and returns the badge #.
        // Used by multiple methods.
        private static int ChooseBadgeKey()
        {
            Console.WriteLine("Choose a badge #: ");

            foreach (int key in BadgeRepository.GetDictionary().Keys)
            {
                Console.WriteLine($"      [{key}]");
            }

            while (true)
            {
                int chosen = int.Parse(Input("Input [#]: "));

                if (BadgeRepository.GetDictionary().ContainsKey(chosen))
                {
                    return(chosen);
                }
            }
        }
Ejemplo n.º 6
0
        // Displays a list of badges along with all doors they can open
        private static void ViewAllBadgesOption()
        {
            foreach (int key in BadgeRepository.GetDictionary().Keys)
            {
                Console.WriteLine($"Badge #{key}:");

                if (BadgeRepository.GetDictionary()[key].Count > 0)
                {
                    Console.WriteLine($"  Can Unlock {string.Join(", ", BadgeRepository.GetDictionary()[key])}");
                }

                else
                {
                    Console.WriteLine("  Cannot Unlock Anything");
                }

                Console.WriteLine();
            }

            Input("Press enter/return when you're done viewing this list ");
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Badge           badge     = new Badge();
            BadgeRepository badgeRepo = new BadgeRepository();
            List <string>   _Doors    = new List <string>();
            Dictionary <int, List <string> > theDictionary = new Dictionary <int, List <string> >();

            Console.WriteLine("Hello Security what would you like to do?\n" +
                              "Select 1 to Add a new badge.\n" +
                              "Select 2 to Update a badge.\n" +
                              "Select 3 to List all badges.");

            string theAnswer = Console.ReadLine();

            while (true)
            {
                if (theAnswer == "1")
                {
                    Console.WriteLine("What is the number on the badge?");
                    var number = int.Parse(Console.ReadLine());
                    Console.WriteLine("What are the doors it needs to access?");
                    var newdoor = Console.ReadLine();
                }

                if (theAnswer == "2")
                {
                }

                if (theAnswer == "3")
                {
                    foreach (KeyValuePair <$"{badge.Id}, {badge.Doors}"> )
                    {
                        Console.WriteLine("");
                    }
                }
            }
        }
Ejemplo n.º 8
0
        // Deletes a badge permanently
        private static void DeleteBadgeOption()
        {
            int current_key = ChooseBadgeKey();

            Console.WriteLine(divider);

            while (true)
            {
                string y_n = Input($"Are you sure you want to delete Badge #{current_key}? (y/n) ").ToLower();

                if (y_n.StartsWith("y"))
                {
                    BadgeRepository.RemoveKeyFromDict(current_key);
                    Console.WriteLine("\nYour badge has been deleted.");
                    Input("Press enter/return ");
                    return;
                }

                else if (y_n.StartsWith("n"))
                {
                    return;
                }
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            Badge           badge     = new Badge();
            BadgeRepository badgeRepo = new BadgeRepository();
            Dictionary <int, List <string> > BadgeID = badgeRepo.GetDictionary();
            List <string> listOne = new List <string>();

            listOne.Add("A1");
            listOne.Add("A2");
            Badge one = new Badge(123, listOne);

            string response = null;

            while (response != "4")
            {
                Console.WriteLine($"Hello Security Admin!\n\nWhat would you like to do?\n\n1. Add a badge\n2. Edit a badge\n3. List all badges\n4. Exit program\n");
                response = Console.ReadLine();
                Console.Clear();
                if (response == "1")
                {
                    Console.WriteLine("Enter badge ID number:");
                    badge.BadgeNum = Int32.Parse(Console.ReadLine());

                    List <String> _newDoorsFromConsole = new List <string>();
                    bool          doorAddLoop          = true;
                    while (doorAddLoop)
                    {
                        Console.WriteLine("Assign new door: (A5, B3, C2, ect.)");
                        var newDoor = Console.ReadLine();
                        _newDoorsFromConsole.Add(newDoor);

                        Console.WriteLine("Would you like to add another door? y/n");
                        var addDoorResponse = Console.ReadLine();

                        if (addDoorResponse == "n")
                        {
                            doorAddLoop = false;
                        }
                    }
                    badge.DoorList = _newDoorsFromConsole;
                    badgeRepo.AddBadgeToDictionary(badge);
                    Console.Clear();
                }
                if (response == "2")
                {
                    Console.WriteLine("Which badge would you like to edit?");
                    var           desiredKey  = Int32.Parse(Console.ReadLine());
                    List <string> newDoorList = BadgeID[desiredKey];
                    var           doorString  = badgeRepo.ListToString(newDoorList);
                    Console.WriteLine($"\nBadge: {desiredKey} has access to doors {doorString}\n");
                    Console.WriteLine($"What would you like to change?\n\t1. Remove a door\n\t2. Add a door\n\t3. Change nothing");
                    var updateResponse = Int32.Parse(Console.ReadLine());
                    if (updateResponse == 1)
                    {
                        Console.WriteLine($"Badge: {desiredKey} has access to doors {doorString}\n\n");
                        string removeResponse = "y";
                        while (removeResponse != "n")
                        {
                            Console.WriteLine("Which door would you like to remove?");
                            var removeDoor = Console.ReadLine();
                            newDoorList.Remove(removeDoor);
                            Console.WriteLine("Would you like to remove another door? y/n");
                            removeResponse = Console.ReadLine();
                        }
                    }
                    else
                    {
                        while (updateResponse == 2)
                        {
                            Console.WriteLine("Enter door to be added.");
                            var newDoor = Console.ReadLine();
                            newDoorList.Add(newDoor);
                            Console.WriteLine("Would you like to add another door? y/n");
                            var newDoorResponse = Console.ReadLine();
                            if (newDoorResponse == "y")
                            {
                                updateResponse = 2;
                            }
                            else
                            {
                                updateResponse = 4;
                            }
                        }
                    }
                    Console.Clear();
                }
                if (response == "3")
                {
                    Console.WriteLine($"Here is a list of current badges: \n\nBadge ID number\t\tDoor Access\n");

                    foreach (KeyValuePair <int, List <string> > newBadgeID in BadgeID)
                    {
                        var doorString = badgeRepo.ListToString(newBadgeID.Value);
                        Console.WriteLine($"{newBadgeID.Key}\t\t{doorString}");
                    }
                    Console.WriteLine("Prese 'enter' to return to main menu.");
                    Console.ReadLine();
                    Console.Clear();
                }
                if (response == "4")
                {
                    break;
                }
            }
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            BadgeRepository badgeRepo = new BadgeRepository();
            Dictionary <int, List <string> > badgeDictionary = badgeRepo.GetDictionary();

            string response = null;

            while (response != "4")
            {
                Console.Clear();
                Console.WriteLine($"Hello Security Admin. What would you like to do?" +
                                  $"\n1. Add a badge" +
                                  $"\n2. Edit a badge" +
                                  $"\n3. List all badges" +
                                  $"\n4. Exit");
                response = Console.ReadLine();

                if (response == "1")
                {
                    Console.Clear();
                    List <string> doorList     = new List <string>();
                    string        doorResponse = "y";

                    Console.Write("What is the number on the badge: ");
                    int badgeNum = Int32.Parse(Console.ReadLine());
                    while (doorResponse != "n")
                    {
                        if (doorResponse == "y")
                        {
                            Console.Write("List a door that it needs access to: ");
                            string newDoor = Console.ReadLine();
                            doorList.Add(newDoor);
                            Console.Write("Are there any other doors? (y/n): ");
                            doorResponse = Console.ReadLine();
                        }
                        else
                        {
                            Console.WriteLine("Invalid Input");
                            Console.Write("Are there any other doors? (y/n): ");
                            doorResponse = Console.ReadLine();
                        }
                    }

                    badgeDictionary.Add(badgeNum, doorList);
                }
                else if (response == "2")
                {
                    Console.Clear();
                    Console.Write("Enter the badge number to edit: ");
                    int editBadge = Int32.Parse(Console.ReadLine());

                    if (badgeDictionary.Keys.Contains(editBadge))
                    {
                        List <string> tempList = badgeDictionary[editBadge];

                        Console.Write($"{editBadge} has access to doors: ");
                        foreach (string door in tempList)
                        {
                            Console.Write($"{door} ");
                        }
                        Console.WriteLine($"\nWhat would you like to do?" +
                                          $"\n\t1. Remove a door" +
                                          $"\n\t2. Add a door");
                        string editDoors = Console.ReadLine();
                        Console.Clear();
                        switch (editDoors)
                        {
                        case "1":
                            Console.WriteLine("Which door would you like to remove?");
                            int count = 0;
                            foreach (string door in tempList)
                            {
                                count++;
                                Console.WriteLine(count + ". " + door);
                            }

                            int removeDoor = Int32.Parse(Console.ReadLine());
                            if (removeDoor > 0)
                            {
                                removeDoor--;
                            }

                            tempList.RemoveAt(removeDoor);
                            Console.Write($"Removed." +
                                          $"\n{editBadge} now has access to: ");
                            foreach (string door in tempList)
                            {
                                Console.Write($"{door} ");
                            }
                            break;

                        case "2":
                            Console.Write("Enter the door you would like to add: ");
                            string addDoor = (Console.ReadLine());
                            tempList.Add(addDoor);
                            Console.WriteLine($"{addDoor} has been added to badge {editBadge}.");
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("There is no badge with that ID.");
                    }
                    Console.ReadLine();
                }
                else if (response == "3")
                {
                    Console.Clear();
                    Console.WriteLine("Key \t\tDoor Access");

                    for (int i = 0; i < badgeDictionary.Count; i++)
                    {
                        string doorListToString = "";
                        int    count            = 0;
                        string comma;
                        foreach (string door in badgeDictionary.Values.ElementAt(i))
                        {
                            count++;
                            if (count < badgeDictionary.Values.ElementAt(i).Count)
                            {
                                comma = ", ";
                            }
                            else
                            {
                                comma = "";
                            }
                            doorListToString = doorListToString + door + comma;
                        }
                        Console.WriteLine($"{badgeDictionary.Keys.ElementAt(i)}\t\t{doorListToString}");
                    }

                    Console.Read();
                }
                else if (response == "4")
                {
                    break;
                }
            }
        }
Ejemplo n.º 11
0
 public ProgramUI()
 {
     _badgeRepository = new BadgeRepository();
 }
Ejemplo n.º 12
0
        private static void ChooseAnOption()
        {
            while (true)
            {
                Console.WriteLine(divider);
                Console.WriteLine("What would you like to do?");
                Console.WriteLine("      [1] Create a new badge");
                Console.WriteLine("      [2] Add a door to a badge");
                Console.WriteLine("      [3] Remove a door from a badge");
                Console.WriteLine("      [4] Delete a badge");
                Console.WriteLine("      [5] View all badges");
                Console.WriteLine("      [6] Exit Program");

                while (true)
                {
                    string chosen = Input("Input [#]: ");

                    if (chosen == "1")
                    {
                        Console.WriteLine(divider);
                        CreateBadgeOption();
                        break;
                    }

                    else if (chosen == "2")
                    {
                        Console.WriteLine(divider);

                        if (BadgeRepository.DoesDictHaveKeys())
                        {
                            AddDoorToBadgeOption();
                        }

                        else
                        {
                            Console.WriteLine("You need to create a badge first.");
                            Input("Press enter/return ");
                        }

                        break;
                    }

                    else if (chosen == "3")
                    {
                        Console.WriteLine(divider);

                        if (BadgeRepository.DoesDictHaveKeys())
                        {
                            RemoveDoorFromBadgeOption();
                        }

                        else
                        {
                            Console.WriteLine("You need to create a badge first.");
                            Input("Press enter/return ");
                        }

                        break;
                    }

                    else if (chosen == "4")
                    {
                        Console.WriteLine(divider);

                        if (BadgeRepository.DoesDictHaveKeys())
                        {
                            DeleteBadgeOption();
                        }

                        else
                        {
                            Console.WriteLine("You need to create a badge first.");
                            Input("Press enter/return ");
                        }

                        break;
                    }

                    else if (chosen == "5")
                    {
                        Console.WriteLine(divider);

                        if (BadgeRepository.DoesDictHaveKeys())
                        {
                            ViewAllBadgesOption();
                        }

                        else
                        {
                            Console.WriteLine("You need to create a badge first.");
                            Input("Press enter/return ");
                        }

                        break;
                    }

                    else if (chosen == "6")
                    {
                        Environment.Exit(1);
                    }
                }
            }
        }