private static bool ShowAllUsersAwards() { int count = 1; foreach (var user in UserManager.GetAllUsers()) { if (UserManager.GetAllUsers().Length == 0) { return(false); } Console.WriteLine($"{count}. {user.ToString()}\nHave Awards:"); foreach (var award in AwardManager.GetUserAwards(user)) { if (award == null) { Console.WriteLine($"Sorry...This user {user.Name} has no awards yet..."); } else { Console.WriteLine($@" ""{award.Name.ToString()}"""); } } count++; } return(true); }
private static void MainInterface() { Console.WriteLine("\nPlase select some action:"); Console.WriteLine("1. Add new User"); Console.WriteLine("2. Remove User!"); Console.WriteLine("3. Show all Users"); Console.WriteLine("4. Add new Award"); Console.WriteLine("5. Remove Award!"); Console.WriteLine("6. Show all Awards"); Console.WriteLine("7. Add Award to User"); Console.WriteLine("8. Show User Awards"); Console.WriteLine("9. Delete all User Awards!"); Console.WriteLine("10. Show all users and their rewards"); Console.WriteLine("11. Change the way data is stored"); Console.WriteLine("12. Exit and Serialize all data in file!"); Console.Write("Enter: "); var menuSelection = Console.ReadLine(); if (uint.TryParse(menuSelection, out uint selectedOption) && selectedOption > 0 && selectedOption < 13) { switch (selectedOption) { case 1: Console.Write("\n1. Enter user Name: "); string userName = Console.ReadLine(); if (string.IsNullOrWhiteSpace(userName)) { Console.WriteLine("\n Name cannot be empty!\n"); Console.ReadKey(); goto case 1; } Console.Write("2. Enter user date of birth by pattern dd.mm.yyyy: "); bool BDateChecked = DateTime.TryParse(Console.ReadLine(), out DateTime dateOfBith); if (BDateChecked && dateOfBith < DateTime.Now) { UserManager.CreateUser(userName, dateOfBith); Console.WriteLine($"\nUser '{userName}' created!\n"); MainInterface(); } else { Console.WriteLine("\n User not created! You cannot have a date of birth later than the present time!"); Console.ReadKey(); goto case 1; } //To DO: BLL - add User break; case 2: Console.WriteLine("\nChoose which User to delete:"); ShowUsersAndAddNumbers(); Console.Write("\nEnter number of User y whant to remove: "); string numberOfUserToRemove = Console.ReadLine(); if (string.IsNullOrWhiteSpace(numberOfUserToRemove)) { Console.WriteLine("\nThis field cannot be empty!"); Console.ReadKey(); goto case 2; } if (!UserIDs.ContainsKey(int.Parse(numberOfUserToRemove))) { Console.WriteLine("\nWrong number of User!"); Console.ReadKey(); goto case 2; } Guid userGuid = UserIDs[int.Parse(numberOfUserToRemove)]; User userToRemove = UserManager.GetUserByID(userGuid); if (UserManager.RemoveUser(userToRemove)) { Console.WriteLine($"\nUser {userToRemove} removed!\n"); Console.WriteLine("Users: "); ShowAllItems(UserManager.GetAllUsers()); Console.ReadKey(); MainInterface(); } else { Console.WriteLine("\nUser deletion failed!\n"); Console.WriteLine("\nPress any button to return to the main menu...\n"); Console.ReadKey(); MainInterface(); } //To DO: BLL - remove User break; case 3: Console.WriteLine("--------------------------------------------------------------------------------"); Console.WriteLine("List all users: "); if (!ShowUsersAndAddNumbers()) { Console.WriteLine("No Users! Add some new User in main menu!"); } Console.WriteLine("--------------------------------------------------------------------------------"); MainInterface(); //To DO: BLL - get all Users // PL - show all Users break; case 4: Console.Write("\nEnter award Name: "); string awardName = Console.ReadLine(); if (string.IsNullOrWhiteSpace(awardName)) { Console.WriteLine("\n Name cannot be empty!\n"); Console.ReadKey(); goto case 4; } if (!AwardManager.AddAward(awardName)) { Console.WriteLine("\nYou cannot create another award with the same name!\n"); Console.ReadKey(); } else { Console.WriteLine($"\nAward '{awardName}' created!\n"); } MainInterface(); //TO DO:BLL - Add Award break; case 5: Console.WriteLine("\nChoose which Award to delete:"); ShowAwardsAndAddNumbers(); Console.Write("\nEnter number of Award y whant to remove: "); string numberOfAwardToRemove = Console.ReadLine(); if (string.IsNullOrWhiteSpace(numberOfAwardToRemove)) { Console.WriteLine("\nThis field cannot be empty!"); Console.ReadKey(); goto case 5; } if (!AwardIDs.ContainsKey(int.Parse(numberOfAwardToRemove))) { Console.WriteLine("Wrong number of User!"); Console.ReadKey(); goto case 5; } Guid awardGuid = AwardIDs[int.Parse(numberOfAwardToRemove)]; Award awardToRemove = AwardManager.GetAwardByID(awardGuid); if (AwardManager.RemoveAward(awardToRemove)) { Console.WriteLine($"\nAward {awardToRemove} removed!\n"); Console.WriteLine("Awards: "); ShowAllItems(AwardManager.GetAllAwards()); Console.ReadKey(); MainInterface(); } else { Console.WriteLine("\nAward deletion failed!\n"); Console.WriteLine("\nPress any button to return to the main menu...\n"); Console.ReadKey(); MainInterface(); } //TO DO:BLL - Remove Award break; case 6: Console.WriteLine("---------------------------------------------------------------------------------"); Console.WriteLine("List all awards: "); if (!ShowAwardsAndAddNumbers()) { Console.WriteLine("No Awards! Add some new Award in main menu!"); } Console.WriteLine("---------------------------------------------------------------------------------"); MainInterface(); //TO DO:BLL - Get All Awards // PL - Show All Awards break; case 7: ShowUsersAndAddNumbers(); Console.Write("\nEnter the USER number to whom you would like to give an award: "); string numberOfUserForAward = Console.ReadLine(); if (string.IsNullOrWhiteSpace(numberOfUserForAward)) { Console.WriteLine("\nThis field cannot be empty!"); Console.ReadKey(); goto case 7; } if (!UserIDs.ContainsKey(int.Parse(numberOfUserForAward))) { Console.WriteLine("Invalid User number!"); goto case 7; } Guid userID = UserIDs[int.Parse(numberOfUserForAward)]; ShowAwardsAndAddNumbers(); Console.Write("\nEnter the AWARD number: "); string numberOfAwardForUser = Console.ReadLine(); if (string.IsNullOrWhiteSpace(numberOfAwardForUser)) { Console.WriteLine("\nThis field cannot be empty!"); Console.ReadKey(); goto case 7; } if (!AwardIDs.ContainsKey(int.Parse(numberOfAwardForUser))) { Console.WriteLine("Invalid Award number!"); return; } Guid awardID = AwardIDs[int.Parse(numberOfAwardForUser)]; if (AwardManager.AddAwardToUser(userID, awardID)) { Console.WriteLine($@"Award - ""{AwardManager.GetAwardByID(awardID).Name}"" successfully added to User {UserManager.GetUserByID(userID).Name}!"); Console.ReadKey(); } else { Console.WriteLine("\nYou cannot revard USER the same AWARD multiple times!"); Console.ReadKey(); Console.Write("\nWant to return to the main menu? y/n "); ConsoleKeyInfo btn = Console.ReadKey(); if (btn.Key == ConsoleKey.Y) { MainInterface(); } goto case 7; } MainInterface(); //TO DO:Bll,PL - Add Award to User break; case 8: ShowUsersAndAddNumbers(); Console.WriteLine("Enter the number of the USER you would like to view awards: "); string numberOfUserToShowAwards = Console.ReadLine(); if (string.IsNullOrWhiteSpace(numberOfUserToShowAwards)) { Console.WriteLine("\nThis field cannot be empty!"); Console.ReadKey(); goto case 8; } if (!UserIDs.ContainsKey(int.Parse(numberOfUserToShowAwards))) { Console.WriteLine("Invalid User number!"); goto case 8; } Guid userToFindByID = UserIDs[int.Parse(numberOfUserToShowAwards)]; User newUserForAward = UserManager.GetUserByID(userToFindByID); Award[] userAwards = AwardManager.GetUserAwards(newUserForAward); Thread.Sleep(50); if (userAwards.Length == 0) { Console.WriteLine(newUserForAward.ToString()); Console.WriteLine($"Sorry...This User {newUserForAward.Name} has no Awards yet, or this Award was deleted..."); } else { Console.WriteLine($"\nUser number {numberOfUserToShowAwards}:\n{newUserForAward.ToString()}\n"); Console.WriteLine($"Has Awards :"); ShowAllItems(userAwards); } //ToDo: Get User Awards - BLL,PL MainInterface(); break; case 9: Console.WriteLine("\nChoose which User Awards to delete:"); ShowUsersAndAddNumbers(); Console.Write("\nEnter number of User: "******"\nThis field cannot be empty!"); Console.ReadKey(); goto case 9; } if (!UserIDs.ContainsKey(int.Parse(userNameToDeleteAllAwards))) { Console.WriteLine("Wrong number of User!"); Console.ReadKey(); goto case 9; } Guid IDToDeleteAwards = UserIDs[int.Parse(userNameToDeleteAllAwards)]; User userIDToDeleteAwards = UserManager.GetUserByID(IDToDeleteAwards); if (AwardManager.DeleteUserAwards(userIDToDeleteAwards)) { Console.WriteLine($"\nAll Users {userIDToDeleteAwards.Name} Awards successfully removed!"); Award[] userAwardsToDelete = AwardManager.GetUserAwards(userIDToDeleteAwards); if (userAwardsToDelete.Length == 0) { Console.WriteLine(userIDToDeleteAwards.ToString()); Console.WriteLine("\nAll Award of this User deleted!"); Console.ReadKey(); MainInterface(); } else { Console.WriteLine("Cant delete this Awards..."); Console.ReadKey(); MainInterface(); } Console.ReadKey(); MainInterface(); } else { Console.WriteLine("User dont have Awards!"); Console.ReadKey(); MainInterface(); } break; case 10: //ToDO: Show All Users Awards-BLL if (!ShowAllUsersAwards()) { Console.WriteLine("No Users! Add some new User in main menu!"); } Console.ReadKey(); MainInterface(); break; case 11: ChangeDALType(); break; case 12: return; } } else { Console.WriteLine("Wrong number!"); MainInterface(); } }