//Create new badge private void CreateNewBadge() { Console.Clear(); Badges newBadge = new Badges(); //BadgeID Console.WriteLine("Please enter the badge ID:"); string input = Console.ReadLine(); int number; bool isNumber = Int32.TryParse(input, out number); bool isTaken = _badgeRepo.badgeDictionary.ContainsKey(number); if (isNumber == true && isTaken == false) { newBadge.BadgeID = number; } else { Console.WriteLine("Please input a valid number\n" + "Press any key to continue"); Console.ReadKey(); CreateNewBadge(); } //Add door names //List all doors Console.WriteLine("Doors available to assign:"); foreach (string doors in _doorList) { Console.WriteLine(doors); } bool doorAssignment = true; while (doorAssignment) { Console.WriteLine("Please input the doors to be assigned to this badge one at a time:"); string doorInput = Console.ReadLine(); if (_doorList.Contains(doorInput)) { newBadge.AddDoorNames(doorInput); Console.WriteLine("Do you wish to add another door assignment?\n" + "Y or N"); string yesOrNo = Console.ReadLine().ToLower(); if (yesOrNo == "y") { doorAssignment = true; } else { doorAssignment = false; } } else { Console.WriteLine("There is no door matching that input. Please try again."); } } Console.WriteLine("Please input the employee's name for this badge:"); bool nameAssignment = true; while (nameAssignment) { string nameInput = Console.ReadLine().ToUpper(); if (nameInput != null) { newBadge.NameOnBadge = nameInput; nameAssignment = false; } else { Console.WriteLine("Please input a valid name:\n" + "Press any key to continue"); Console.ReadKey(); } } _badgeRepo.AddBadges(newBadge.BadgeID, newBadge); }
//Edit badge private void EditBadge() { Console.Clear(); bool isEditing = true; while (isEditing) { //Display active badges ViewActiveBadges(); //Elicit input from user Console.WriteLine("\n" + "Please input the badge ID you wish to edit:"); string inputID = Console.ReadLine(); int number; bool isNumber = Int32.TryParse(inputID, out number); if (isNumber == true) { Badges newBadge = new Badges(); Dictionary <int, Badges> _badgeCollection = _badgeRepo.badgeDictionary; if (_badgeCollection.ContainsKey(number)) { Console.Clear(); Console.WriteLine($"Badge ID: {_badgeCollection[number].BadgeID}\n" + $"Doors Assigned: "); string doorNames = null; foreach (string doors in _badgeCollection[number].DoorNames) { doorNames = doors; Console.WriteLine($"| {doorNames} | "); } Console.WriteLine($"Employee: {_badgeCollection[number].NameOnBadge}\n" + $"_____________________"); Console.WriteLine( $"Please choose an edit option:\n" + $"1. Add door assignments\n" + $"2. Remove door assignments\n" + $"3. Remove badge from system\n" + $"4. Return to main menu\n" + $"\n"); string input = Console.ReadLine(); switch (input) { case "1": //Add doors AddDoors(); break; case "2": //Remove doors RemoveDoors(); break; case "3": //Delete badge RemoveBadge(); break; case "4": //Main menu isEditing = false; Menu(); break; default: Console.WriteLine("Please enter a valid option"); break; } void AddDoors() { //List all doors Console.WriteLine("Doors available to assign:"); foreach (string doors in _doorList) { Console.WriteLine(doors); } bool doorAssignment = true; while (doorAssignment) { Console.WriteLine("Please input the doors to be assigned to this badge one at a time:"); string doorInput = Console.ReadLine(); if (_doorList.Contains(doorInput)) { Badges oldBadge = _badgeCollection[number]; oldBadge.AddDoorNames(doorInput); newBadge = oldBadge; bool wasUpdated = _badgeRepo.UpdateBadges(oldBadge.BadgeID, newBadge); if (wasUpdated == true) { Console.WriteLine("Badge successfully updated!"); Console.WriteLine("Do you wish to add another door assignment?\n" + "Y or N"); string yesOrNo = Console.ReadLine().ToLower(); if (yesOrNo == "y") { doorAssignment = true; } else if (yesOrNo == "n") { doorAssignment = false; } } else { Console.WriteLine("Could not update badge."); doorAssignment = false; } } else { Console.WriteLine("There is no door matching that input. Please try again."); } } } void RemoveDoors() { bool doorRemoval = true; while (doorRemoval) { Console.WriteLine("Please input the doors to be removed one at time:"); string doorInput = Console.ReadLine(); if (_doorList.Contains(doorInput)) { Badges oldBadge = _badgeCollection[number]; newBadge = oldBadge; bool wasUpdated = _badgeRepo.RemoveDoorsFromBadge(oldBadge.BadgeID, doorInput); if (wasUpdated == true) { Console.WriteLine("Badge successfully updated!"); Console.WriteLine("Do you wish to remove another door assignment?\n" + "Y or N"); string yesOrNo = Console.ReadLine().ToLower(); if (yesOrNo == "y") { doorRemoval = true; } else if (yesOrNo == "n") { doorRemoval = false; } } else { Console.WriteLine("Could not update badge."); doorRemoval = false; } } } } void RemoveBadge() { bool badgeRemoval = true; while (badgeRemoval) { Console.WriteLine("Are you sure you want to remove this badge from the system?\n" + "Y or N\n" + "\n"); string userInput = Console.ReadLine().ToLower(); if (userInput == "y") { Badges oldBadge = _badgeCollection[number]; bool wasRemoved = _badgeRepo.RemoveBadge(oldBadge.BadgeID); if (wasRemoved == true) { Console.WriteLine("Badge successfully removed!\n" + "Press any key to continue\n" + "\n"); Console.ReadKey(); badgeRemoval = false; isEditing = false; Menu(); } } else { badgeRemoval = false; } } } } else { Console.WriteLine("There was no badge with that ID. Please input a valid number.\n" + "Press any key to continue"); Console.ReadKey(); EditBadge(); } } else { Console.WriteLine("We could not find anything based on that input. Please try again with an appropriate number.\n" + "Press any key to continue"); Console.ReadKey(); isEditing = false; Menu(); } } }