public bool AddBadge(Badges newBadge) { int startingcount = _badges.Count; _badges.Add(newBadge); bool wasAdded = (_badges.Count > startingcount) ? true : false; return(wasAdded); }
private void AddABadge() { Console.Clear(); Badges newBadge = new Badges(); Console.WriteLine("Please enter a badge number"); string badgeIDAsString = Console.ReadLine(); int badgeIDAsInt = Convert.ToInt32(badgeIDAsString); newBadge.BadgeID = badgeIDAsInt; Console.WriteLine("What doors does this badge need access to?\n" + "1. A1\n" + "2. A2\n" + "3. A3\n" + "4. A4\n" + "5. A5\n" + "6. A6\n" + "7. A7\n" + "8. A8\n" + "9. A9"); newBadge.TypeOfDoor = new List <DoorType>; Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Does this badge need access to any other doors? (y/n)"); if (Console.ReadKey().KeyChar == 'y') { Console.Clear(); Console.WriteLine("What doors does this badge need access to?\n" + "1. A1\n" + "2. A2\n" + "3. A3\n" + "4. A4\n" + "5. A5\n" + "6. A6\n" + "7. A7\n" + "8. A8\n" + "9. A9"); newBadge.TypeOfDoor = new List <DoorType>; Convert.ToInt32(Console.ReadLine()); } else { Console.Clear(); } bool wasAdded = _repo.AddBadge(newBadge); if (wasAdded) { Console.WriteLine("The Badge was entered successfully"); } else { Console.WriteLine("The badge was not entered correctly, please try again"); } }
//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(); } } }