Пример #1
0
        private void EditABadge()
        {
            Console.WriteLine("What is the badge number to update?:");
            string input            = Console.ReadLine();
            bool   selectionIsValid = false;
            bool   preExistingID    = false;
            int    currentID        = 0;
            int    badgeNumberInt   = 0;

            while (!selectionIsValid)
            {
                if (!int.TryParse(input, out badgeNumberInt))
                {
                    Console.WriteLine("Please enter a valid badge number.");
                    input = Console.ReadLine();
                    continue;
                }
                Dictionary <int, List <Door> > _currentDictionary = new Dictionary <int, List <Door> >();
                _currentDictionary = _badgeRepo.GetBadgeDictionary();
                foreach (KeyValuePair <int, List <Door> > keyValue in _currentDictionary)
                {
                    if (keyValue.Key == badgeNumberInt)
                    {
                        currentID     = keyValue.Key;
                        preExistingID = true;
                    }
                }
                if (!preExistingID)
                {
                    Console.WriteLine("That badge does not exist.");
                    continue;
                }
                bool selectionValid = false;
                while (!selectionValid)
                {
                    Console.WriteLine($"What would you like to do?\n" +
                                      $"1. Remove a door\n" +
                                      $"2. Remove all doors\n" +
                                      $"3. Add a door\n" +
                                      $"4. Exit");
                    string userInput = Console.ReadLine().ToLower();
                    switch (userInput)
                    {
                    case "1":
                        Console.WriteLine("This badge has access to doors:");
                        foreach (KeyValuePair <int, List <Door> > keyValue in _currentDictionary)
                        {
                            if (keyValue.Key == currentID)
                            {
                                foreach (Door door in keyValue.Value)
                                {
                                    Console.WriteLine(door.DoorName);
                                }
                            }
                        }
                        Console.WriteLine("Which door would you like to remove:");
                        string doorToRemove = Console.ReadLine();
                        if (!_badgeRepo.RemoveDoorFromBadge(currentID, doorToRemove))
                        {
                            Console.WriteLine("Door not recognized.");
                            continue;
                        }
                        Console.WriteLine($"Door {doorToRemove} removed successfully.");
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey();
                        selectionValid = true;
                        break;

                    case "2":
                        _badgeRepo.RemoveAllDoors(currentID);
                        Console.WriteLine($"All doors have been removed from badge.");
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey();
                        selectionValid = true;
                        break;

                    case "3":
                        Console.WriteLine("List doors that it needs access to (separate doors by commas):");
                        userInput = Console.ReadLine();
                        userInput = userInput.Replace(" ", "");
                        userInput = userInput.Trim();
                        string[]    doorsArray        = userInput.Split(',');
                        List <Door> newDoorAccessList = new List <Door>();
                        foreach (string door in doorsArray)
                        {
                            //Need to add to current door instead of adding a new door. having issues.
                            Door newDoor = new Door {
                                DoorName = door
                            };
                            newDoorAccessList.Add(newDoor);
                        }
                        Badge newBadgeExample = new Badge(badgeNumberInt, newDoorAccessList);
                        _badgeRepo.AddBadgeToBadgeDictionary(newBadgeExample);
                        Console.WriteLine("New badge successfully added.");
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey();
                        selectionValid = true;
                        break;

                    case "4":
                        selectionValid = true;
                        break;

                    default:
                        Console.WriteLine("Please try again.");
                        continue;
                    }
                }
                selectionIsValid = true;
            }
        }
Пример #2
0
        private void EditBadge()
        {
            Console.Clear();
            Console.WriteLine("Type the ID# of the Badge you want to edit, then press enter");
            Dictionary <int, List <Doors> > badges = _badgeRepo.GetBadges();

            foreach (var id in badges)
            {
                Console.WriteLine($"Badge ID: {id.Key}");
            }
            int userInput = Convert.ToInt32(Console.ReadLine());

            foreach (var id in badges.Keys)
            {
                if (userInput == id)
                {
                    badges.Remove(id);
                    Console.Clear();
                    Badge        myBadge  = new Badge();
                    List <Doors> doorList = new List <Doors>();
                    Doors        access   = new Doors();
                    Console.WriteLine("Re-Enter Badge Number: ");
                    myBadge.Id = Convert.ToInt32(Console.ReadLine());
                    bool keepThinking = true;
                    while (keepThinking)
                    {
                        Console.Clear();
                        Console.WriteLine("Which doors would you like to add to this Badge \n" +
                                          "Level A: A1, A2, A3, A4 \n" +
                                          "Level B: B1, B2, B3, B4 \n" +
                                          "Type x and hit enter to exit Menu");
                        string userChoice = Console.ReadLine();
                        switch (userChoice)
                        {
                        case "A1":
                            access.GetDoor1();
                            break;

                        case "A2":
                            access.GetDoor2();
                            break;

                        case "A3":
                            access.GetDoor3();
                            break;

                        case "A4":
                            access.GetDoor4();
                            break;

                        case "B1":
                            access.GetDoor5();
                            break;

                        case "B2":
                            access.GetDoor6();
                            break;

                        case "B3":
                            access.GetDoor7();
                            break;

                        case "B4":
                            access.GetDoor8();
                            break;

                        case "x":
                            keepThinking = false;
                            break;

                        default:
                            Console.WriteLine("Invalid");
                            Console.ReadKey();
                            break;
                        }
                    }
                    doorList.Add(access);
                    myBadge.DoorsList = doorList;
                    _badgeRepo.AddBadge(myBadge);
                    break;
                }
                else
                {
                    Console.WriteLine("Invalid");
                }
            }



            Console.WriteLine("Press any key to continue.........");
            Console.ReadKey();
        }
Пример #3
0
        private void AddNewBadge()
        {
            Console.Clear();
            Badge        myBadge  = new Badge();
            List <Doors> doorList = new List <Doors>();
            Doors        access   = new Doors();

            Console.WriteLine("Enter Badge Number: ");
            myBadge.Id = Convert.ToInt32(Console.ReadLine());
            bool keepThinking = true;

            while (keepThinking)
            {
                Console.Clear();
                Console.WriteLine("Which doors would you like to add to this Badge \n" +
                                  "Level A: A1, A2, A3, A4 \n" +
                                  "Level B: B1, B2, B3, B4 \n" +
                                  "Type x and hit enter to exit Menu");
                string userInput = Console.ReadLine();
                switch (userInput)
                {
                case "A1":
                    access.GetDoor1();
                    break;

                case "A2":
                    access.GetDoor2();
                    break;

                case "A3":
                    access.GetDoor3();
                    break;

                case "A4":
                    access.GetDoor4();
                    break;

                case "B1":
                    access.GetDoor5();
                    break;

                case "B2":
                    access.GetDoor6();
                    break;

                case "B3":
                    access.GetDoor7();
                    break;

                case "B4":
                    access.GetDoor8();
                    break;

                case "x":
                    keepThinking = false;
                    break;

                default:
                    Console.WriteLine("Invalid");
                    Console.ReadKey();
                    break;
                }
            }
            doorList.Add(access);
            myBadge.DoorsList = doorList;

            Console.WriteLine("Press any key to continue.........");
            Console.ReadKey();
            _badgeRepo.AddBadge(myBadge);
        }
Пример #4
0
 public void AddBadge(Badge badge)
 {
     _badge.Add(badge.BadgeID, badge.AccessibleDoors);
 }