public void Run()
        {
            Badge one = new Badge(1, new List <string>()
            {
                "a1", "a5", "d4"
            });
            Badge two = new Badge(2, new List <string>()
            {
                "a1", "a4", "b1", "b2"
            });
            Badge three = new Badge(3, new List <string>()
            {
                "a4", "a5"
            });

            _badgeRepo.AddBadge(one);
            _badgeRepo.AddBadge(two);
            _badgeRepo.AddBadge(three);
            bool isRunning = true;

            while (isRunning)
            {
                Console.WriteLine("Welcome to Komodo Security." +
                                  "\nSelect a menu option: \n" +
                                  "\n1. Add another Badge" +
                                  "\n2. Edit/Remove doors on an existing badge" +
                                  "\n3. Show all badges and their assigned doors" +
                                  "\n0. Exit");
                int input = int.Parse(Console.ReadLine());
                switch (input)
                {
                case 1:
                    AddBadge();
                    break;

                case 2:
                    EditBadgeDoors();
                    break;

                case 3:
                    ShowAllBadges();
                    break;

                case 0:
                    isRunning = false;
                    break;

                default:
                    Console.WriteLine("Invalid Option");
                    break;
                }
            }
        }
Beispiel #2
0
        public override bool OnKeyPress(ConsoleKeyInfo keyInfo)
        {
            if (base.OnKeyPress(keyInfo))
            {
                return(true);
            }

            ConsoleKey key = keyInfo.Key;

            switch (key)
            {
            case ConsoleKey.UpArrow:
                index--;
                if (index < 0)
                {
                    index = MaxIndex - 1;
                }
                return(true);

            case ConsoleKey.DownArrow:
                index++;
                if (index >= MaxIndex)
                {
                    index = 0;
                }
                return(true);

            case ConsoleKey.N:
                Console.Clear();
                Console.WriteLine("What doors should this new badge open (separate with commas):");
                string[] doors = Console.ReadLine().Split(',');
                badges.AddBadge(new Badge(doors));
                return(true);

            case ConsoleKey.C:
                badges.GetBadge(index).ClearAccess();
                return(true);

            case ConsoleKey.E:
                new BadgeEditScreen(badges.GetBadge(index)).Run();
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        private void CreateBadge()
        {
            Console.WriteLine("Please enter badge ID");

            string inputBadgeId = Console.ReadLine();
            int    badgeId;

            while (!int.TryParse(inputBadgeId, out badgeId))
            {
                Console.WriteLine("Please enter a valid number for Badge ID");
                inputBadgeId = Console.ReadLine();
            }
            Dictionary <int, List <string> > dictionary = _badgeRepository.GetDictionary();

            if (dictionary.ContainsKey(badgeId))
            {
                Console.WriteLine("badge ID " + badgeId + " already exist.");
            }
            else
            {
                Console.WriteLine("how many doors can this badge open?");
                string inputNumberOfDoor = Console.ReadLine();
                int    numberOfDoors;
                while (!int.TryParse(inputNumberOfDoor, out numberOfDoors) || numberOfDoors < 1)
                {
                    Console.WriteLine("Please enter a valid number greater than zero (0) for number of doors");
                    inputNumberOfDoor = Console.ReadLine();
                }
                List <string> listOfDoors = new List <string>();

                for (int i = 0; i < numberOfDoors; i++)
                {
                    Console.WriteLine("Enter door name for door #" + (i + 1));
                    string doorName = Console.ReadLine();
                    listOfDoors.Add(doorName);
                }

                _badgeRepository.AddBadge(badgeId, listOfDoors);
            }
            NextMessage();
        }