public static void UserMode() { while (true) { ConsoleDisplay.UserMenuDisplay(); if (!int.TryParse(Console.ReadLine(), out int input)) { Console.WriteLine("Incorrect input. Try again!"); continue; } switch (input) { case 1: { User user = CreateUser(); _userLogic.Add(user); Console.WriteLine("User added with ID - {0}", user.Id); Console.ReadLine(); break; } case 2: { int id = GetId(); User user = _userLogic.GetById(id); ShowUser(user); Console.ReadLine(); break; } case 3: { ShowAllUsers(); Console.ReadLine(); break; } case 4: { int id = GetId(); if (_userLogic.RemoveById(id)) { Console.WriteLine("User with ID - {0} is deleted.", id); } else { Console.WriteLine("User with this ID does not exist."); } Console.ReadLine(); break; } case 5: { ShowAllUsers(); Console.WriteLine("Select user for rewarding."); User user = _userLogic.GetById(GetId()); if (user == null) { Console.WriteLine("User with this ID does not exist."); break; } Console.WriteLine("List of awards:"); ShowAllAwards(); Console.WriteLine("Select award for rewarding."); Award award = _awardLogic.GetById(GetId()); if (award == null) { Console.WriteLine("Award with this ID does not exist."); break; } if (_userLogic.GiveAward(user.Id, award)) { Console.WriteLine("The award was successfully presented."); } else { Console.WriteLine("An error occurred during the presentation of award."); } Console.ReadLine(); break; } case 6: { ShowAllUsers(); Console.WriteLine("Select user to take award from."); User user = _userLogic.GetById(GetId()); if (user == null) { Console.WriteLine("User with this ID does not exist."); break; } ShowAllAwards(); Console.WriteLine("Select award to take from user."); Award award = _awardLogic.GetById(GetId()); if (award == null) { Console.WriteLine("Award with this ID does not exist."); break; } if (_userLogic.TakeAwayAward(user.Id, award.Id)) { _awardLogic.RemoveUserFromAward(awardId: award.Id, userId: user.Id); Console.WriteLine("The award {0} has been taken from user {1}.", award.Title, user.Name); } else { Console.WriteLine("Can't take award."); } Console.ReadLine(); break; } case 0: break; default: break; } if (input == 0) { break; } Console.Clear(); } }
private static void UserMode() { while (true) { ShowUserMenu(); if (!int.TryParse(Console.ReadLine(), out int selectUser)) { Console.WriteLine("Incorrect input. Try again."); continue; } switch (selectUser) { // add new user case 1: { User user = CreateUser(); _userLogic.Add(user); Console.WriteLine($"User added. User's ID is {user.Id}"); Console.ReadLine(); break; } // get user by id case 2: { int id = GetId(); User user = _userLogic.GetById(id); ShowUser(user); Console.ReadLine(); break; } // show all users case 3: { ShowAllUsers(); Console.ReadLine(); break; } // remove user by id case 4: { int id = GetId(); if (_userLogic.RemoveById(id)) { Console.WriteLine($"User with ID = {id} is removed."); } else { Console.WriteLine(NO_USER_ID); } Console.ReadLine(); break; } // give award to user case 5: { ShowAllUsers(); Console.WriteLine("Select User to give Award to."); User user = _userLogic.GetById(GetId()); if (user == null) { Console.WriteLine(NO_USER_ID); break; } ShowAllAwards(); Console.WriteLine("Select Award to give to the User."); Award award = _awardLogic.GetById(GetId()); if (award == null) { Console.WriteLine(NO_AWARD_ID); break; } if (_userLogic.GiveAward(user.Id, award.Id)) { _awardLogic.AddUserToAward(awardId: award.Id, userId: user.Id); Console.WriteLine($"The Award \"{award.Title}\" has been given to the User \"{user.Name}\"."); } else { Console.WriteLine($"Can't give the Award \"{award.Title}\" to the User \"{user.Name}\"."); } Console.ReadLine(); break; } // take award from user case 6: { ShowAllUsers(); Console.WriteLine("Select User to take Award from."); User user = _userLogic.GetById(GetId()); if (user == null) { Console.WriteLine(NO_USER_ID); break; } ShowAllAwards(); Console.WriteLine("Select Award to take from the User."); Award award = _awardLogic.GetById(GetId()); if (award == null) { Console.WriteLine(NO_AWARD_ID); break; } if (_userLogic.TakeAwayAward(user.Id, award.Id)) { _awardLogic.RemoveUserFromAward(awardId: award.Id, userId: user.Id); Console.WriteLine($"The Award \"{award.Title}\" has been taken from the User \"{user.Name}\"."); } else { Console.WriteLine($"Can't take the Award \"{award.Title}\" from the User \"{user.Name}\"."); } Console.ReadLine(); break; } // exit case 0: break; default: { Console.WriteLine("Wrong number. Try again."); Console.ReadLine(); break; } } if (selectUser == 0) { break; } Console.Clear(); } }