Exemplo n.º 1
0
        public Badges AddRoomHelper(int badgeID)
        {
            Badges        newUpdateBadge = new Badges();
            List <string> addAccess      = new List <string>();

            newUpdateBadge.BadgeID = badgeID;

            bool doorAccessDone = true;

            while (doorAccessDone)
            {
                Console.WriteLine("Which room do we need to Add?");
                addAccess.Add(Console.ReadLine());

                newUpdateBadge.DoorAccess = addAccess;

                Console.WriteLine("Add another room? (y/n)");
                string inputaddAnotherDoor = Console.ReadLine();
                bool   yesAddAnotherDoor   = "y".Equals(inputaddAnotherDoor, StringComparison.OrdinalIgnoreCase);
                if (yesAddAnotherDoor == true)
                {
                    doorAccessDone = true;
                }
                else
                {
                    doorAccessDone = false;
                }
            }

            return(newUpdateBadge);
        }
Exemplo n.º 2
0
        public Badges GetBadgeToCreate()
        {
            Badges badgeToCreate = new Badges();
            Random randID        = new Random();

            badgeToCreate.badgeID = randID.Next(1000, 10000);
            List <string> access    = new List <string>();
            bool          moreDoors = true;

            while (moreDoors)
            {
                Console.WriteLine("What doors are to be accessed?");
                string doors = Console.ReadLine();
                access.Add(doors);
                Console.WriteLine("\nMore doors?");
                string r = Console.ReadLine().ToLower();

                if (r == "n" || r == "no")
                {
                    moreDoors = false;
                    Console.Clear();
                }
                else if (r != "y" && r != "yes")
                {
                    Console.WriteLine("\nPlease enter [y] or [n]");
                    Console.ReadLine();
                    Console.Clear();
                }
            }
            badgeToCreate.badgeAccess = access;
            return(badgeToCreate);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Badges managebadges = new Badges();

            managebadges.createNewBadge();
            managebadges.listAllBadges();
            Console.ReadLine();
        }
Exemplo n.º 4
0
        } //End of Menu

        public void CreateBadge()
        {
            Badges        newBadge  = new Badges();
            List <string> newAccess = new List <string>();


            bool inBadgecheckLoop = true;

            while (inBadgecheckLoop)
            {
                Console.Clear();
                Console.WriteLine("What is the badge number:");
                var input = Console.ReadLine();


                if (Int32.TryParse(input, out int number)) // turns a string into int if it can
                {
                    newBadge.BadgeID = number;             // takes the number and adds it to Badges
                    inBadgecheckLoop = false;              // sets check the badge to false
                }
                else
                {
                    Console.WriteLine($"The Badge ID, {input}, is not a number. Please try again. Press Enter to continue....");
                    Console.ReadKey();
                    inBadgecheckLoop = true;
                }
            }

            bool doorAccessDone = true;

            while (doorAccessDone)
            {
                Console.WriteLine("Which door needs access?");
                newAccess.Add(Console.ReadLine());
                newBadge.DoorAccess = newAccess; // adds door to List Door Acccess



                Console.WriteLine("Add another door? (y/n)");
                string inputAddAnotherDoor = Console.ReadLine();
                bool   yesAddAnotherDoor   = "y".Equals(inputAddAnotherDoor, StringComparison.OrdinalIgnoreCase);
                if (yesAddAnotherDoor == true)
                {
                    doorAccessDone = true;
                }
                else
                {
                    doorAccessDone = false;
                }
            }


            _badgesRepo.AddToAccessList(newBadge);  // Sends BadgeID and DoorAccess to repo for insertion
        } // End of Create New Badge
Exemplo n.º 5
0
        public void AddARoom(int badgeID)
        {
            Badges newUpdateBadge = AddRoomHelper(badgeID);

            bool wasUpdated = _badgesRepo.AddRoomToBadge(newUpdateBadge);

            if (wasUpdated)
            {
                Console.WriteLine("Room was successfully added.");
            }
            else
            {
                Console.WriteLine("Room access was not updated.");
            }
        }
Exemplo n.º 6
0
        public void SeedBadgeDictionary()
        {
            List <string> list1 = new List <string>();  // Need to create a list

            list1.Add("Room 2");
            list1.Add("Room 4");

            var badge1 = new Badges(1, list1);

            _badgesRepo.AddToAccessList(badge1);

            List <string> list2 = new List <string>();

            list2.Add("Room 3");
            list2.Add("Room 4");

            var badge2 = new Badges(2, list2);

            _badgesRepo.AddToAccessList(badge2);
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            Badges managebadges = new Badges();

            Console.WriteLine("Hello Security Admin. What would you like to do? Select the number that corresponds to the menu option and press enter.");
            Console.WriteLine("1.)Add a badge.\n2.)Update a badge.\n3.)List all badges.");
            int choice = int.Parse(Console.ReadLine());

            while (choice != 4)
            {
                switch (choice)
                {
                case 1:
                {
                    managebadges.createNewBadge();
                    break;
                }

                case 2:
                {
                    managebadges.UpdateBadge();
                    break;
                }

                case 3:
                {
                    managebadges.listAllBadges();
                    break;
                }

                case 4:
                {
                    break;
                }
                }
                Console.WriteLine("Hello Security Admin. What would you like to do? Select the number that corresponds to the menu option and press enter.");
                Console.WriteLine("1.)Add a badge.\n2.)Edit a badge.\n3.)List all badges.");
                choice = int.Parse(Console.ReadLine());
            }
            Console.ReadLine();
        }
Exemplo n.º 8
0
        public void RemoveARoom(int badgeID)
        {
            Badges        newUpdateBadge = new Badges();
            List <string> removeAccess   = new List <string>();

            newUpdateBadge.BadgeID = badgeID;

            bool doorAccessDone = true;

            while (doorAccessDone)
            {
                Console.WriteLine("Which room do we need to remove?");
                removeAccess.Add(Console.ReadLine());

                newUpdateBadge.DoorAccess = removeAccess;

                Console.WriteLine("Remove another room? (y/n)");
                string inputRemoveAnotherDoor = Console.ReadLine();
                bool   yesRemoveAnotherDoor   = "y".Equals(inputRemoveAnotherDoor, StringComparison.OrdinalIgnoreCase);

                if (yesRemoveAnotherDoor == true)
                {
                    doorAccessDone = true;
                }
                else
                {
                    doorAccessDone = false;
                }
            }
            bool wasUpdated = _badgesRepo.RemoveRoomToBadge(newUpdateBadge);

            if (wasUpdated)
            {
                Console.WriteLine("Room was successfully removed.");
            }
            else
            {
                Console.WriteLine("Room access was not updated.");
            }
        }
Exemplo n.º 9
0
        public Badges GetBadgeToUpdate(Badges badgeToUpdate)
        {
            Console.Clear();
            Console.WriteLine($"Badge {badgeToUpdate.badgeID} has access to doors {string.Join(", ", badgeToUpdate.badgeAccess)}.\n");
            Console.WriteLine("1. Add a door \n" +
                              "2. Remove a door");
            int  r         = Convert.ToInt32(Console.ReadLine());
            bool moreDoors = true;

            switch (r)
            {
            case 1:
                while (moreDoors)
                {
                    Console.WriteLine($"Badge {badgeToUpdate.badgeID} currently has access to doors {string.Join(", ", badgeToUpdate.badgeAccess)}.\n");
                    Console.WriteLine("What door should be accessible?");
                    string door = Console.ReadLine();
                    if (!badgeToUpdate.badgeAccess.Contains(door))
                    {
                        badgeToUpdate.badgeAccess.Add(door);
                        Console.WriteLine("\nAdd another door?");
                        string response = Console.ReadLine().ToLower();

                        switch (response)
                        {
                        case "y":
                        case "yes":
                            break;

                        case "n":
                        case "no":
                            moreDoors = false;
                            break;

                        default:
                            Console.WriteLine("\nPlease enter [y] or [n]");
                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Badge # {badgeToUpdate.badgeID} now has access to that door.\n" +
                                          $"Please try again.");
                        Console.ReadLine();
                        Console.Clear();
                    }
                }
                break;

            case 2:
                while (moreDoors)
                {
                    Console.WriteLine($"Badge {badgeToUpdate.badgeID} has access to doors {string.Join(", ", badgeToUpdate.badgeAccess)}.\n");
                    Console.WriteLine("What door would you like to remove?");
                    string door = Console.ReadLine();
                    if (badgeToUpdate.badgeAccess.Contains(door))
                    {
                        badgeToUpdate.badgeAccess.Remove(door);
                        Console.WriteLine("\nRemove another door?");
                        string response = Console.ReadLine().ToLower();

                        if (response == "n" || response == "no")
                        {
                            moreDoors = false;
                        }
                        else if (response != "y" && response != "yes")
                        {
                            Console.WriteLine("\nPlease enter [y] or [n]");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Badge # {badgeToUpdate.badgeID} does not currently have access to that door.\n" +
                                          $"Please try again.");
                        Console.ReadLine();
                        Console.Clear();
                    }
                }
                break;

            default:
                Console.WriteLine("Please enter a valid option.");
                Console.ReadLine();
                Console.Clear();
                break;
            }
            return(badgeToUpdate);
        }
Exemplo n.º 10
0
        public void Run()
        {
            bool running = true;

            while (running)
            {
                Console.Clear();
                Console.WriteLine("Welcome. Please choose option:\n" +
                                  "1. Create a new badge\n" +
                                  "2. View all badges \n" +
                                  "3. Edit a badge \n" +
                                  "4. Exit");
                string userInput = Console.ReadLine();
                Console.Clear();
                switch (Convert.ToInt32(userInput))
                {
                case 1:
                    _helper = new UserInputHelper();
                    Badges badgeToCreate = _helper.GetBadgeToCreate();
                    _badges.CreateBadge(badgeToCreate);

                    if (_badges._allBadges.ContainsKey(badgeToCreate.badgeID))
                    {
                        Console.WriteLine("Your badge was successfully added.\n" +
                                          "Press any key to return to the main menu.");
                        Console.ReadLine();
                        Console.Clear();
                    }
                    else
                    {
                        Console.WriteLine("Your badge could not be added. Please try again.");
                        Console.ReadLine();
                        Console.Clear();
                    }
                    break;

                case 2:
                    _helper = new UserInputHelper();
                    if (_badges._allBadges.Count > 0)
                    {
                        Dictionary <int, List <string> > repoToView = _helper.GetRepoToView(_badges);
                        _badges.ViewAllBadges(repoToView);
                        Console.WriteLine("Press any key to return to the main menu.");
                        Console.ReadLine();
                        Console.Clear();
                    }
                    else
                    {
                        Console.WriteLine("There are currently no badges in this system.\n" +
                                          "Press any key to return to the main menu.");
                        Console.ReadLine();
                        Console.Clear();
                    }
                    break;

                case 3:
                    if (_badges._allBadges.Count > 0)
                    {
                        Console.WriteLine("{0, -15}", "Badge");
                        foreach (KeyValuePair <int, List <string> > item in _badges._allBadges)
                        {
                            Console.WriteLine(item.Key.ToString());
                        }

                        Console.WriteLine("Which badge would you like to edit?");
                        int badge = Convert.ToInt32(Console.ReadLine());

                        if (_badges._allBadges.ContainsKey(badge))
                        {
                            Badges badgeToUpdate = new Badges();
                            badgeToUpdate.badgeID     = badge;
                            badgeToUpdate.badgeAccess = _badges._allBadges[badge];
                            _helper.GetBadgeToUpdate(badgeToUpdate);
                            _badges.EditBadge(badgeToUpdate);

                            Console.WriteLine($"Badge {badgeToUpdate.badgeID} now has access to doors {string.Join(", ", badgeToUpdate.badgeAccess)}.\n");
                            Console.ReadLine();
                            Console.Clear();
                        }
                        else
                        {
                            Console.WriteLine("That badge could not be found.\n" +
                                              "Press any key to return to the main menu.");
                            Console.ReadLine();
                            Console.Clear();
                        }
                    }
                    else
                    {
                        Console.WriteLine("There are currently no badges in this system.\n" +
                                          "Press any key to return to the main menu.");
                        Console.ReadLine();
                        Console.Clear();
                    }
                    break;

                case 4:
                    running = false;
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Please choose a valid option.\n" +
                                      "Press any key to return to try again.");
                    Console.ReadLine();
                    Console.Clear();
                    break;
                }
            }
        }
Exemplo n.º 11
0
 public void EditBadge(Badges badgeToUpdate)
 {
     _allBadges[badgeToUpdate.badgeID] = badgeToUpdate.badgeAccess;
 }
Exemplo n.º 12
0
 public void CreateBadge(Badges badgeToCreate)
 {
     _allBadges.Add(badgeToCreate.badgeID, badgeToCreate.badgeAccess);
 }