public void DeleteUser(int id) { Console.WriteLine(DesignedStrings.DeleteUsr); List <User> UsersList = DB.GetAllUsers(); UserChoice Choice = ConsoleMenu.GetUserChoice(UsersList.Select(usr => usr.Username).ToList(), "Choose the right User for you "); string usernameForDelete; //Console.WriteLine("Choose the username of the user you would like to delete:"); usernameForDelete = Console.ReadLine(); if (usernameForDelete is null) { return; } if (!DoesUsernameExist(usernameForDelete)) // Check if username already exists in database { Console.WriteLine("We are so sorry but the username you entered does not exist.\nPlease choose another user to delete."); Console.ReadKey(); } else { User ToBeDeleted = FindUserViaUsername(usernameForDelete); if (ToBeDeleted.Role == UserAccess.SuperAdministrator) { Console.WriteLine("\n\nPress any key to go back to Super Admin Menu."); Console.ReadKey(); return; } bool userActive = IsUserActive(usernameForDelete); if (!userActive) { Console.WriteLine($"\nThe user with username '{usernameForDelete}' is no longer active."); Console.WriteLine("\n\nPress any key to go back to Menu."); Console.ReadKey(); } else { using (var context = new IMEntities()) { User ToDelete = context.Users.FirstOrDefault(usr => usr.Id == ToBeDeleted.Id); context.Users.Remove(ToDelete); context.SaveChanges(); } Console.WriteLine($"\nUser '{usernameForDelete}' is no longer active ."); Console.WriteLine("\n\nPress any key to go back to Menu."); Console.ReadKey(); } } }
public User SelectUser() { List <User> UsersList = DB.GetAllUsers(); UserChoice Choice = ConsoleMenu.GetUserChoice(UsersList.Select(usr => usr.Username).ToList(), "Choose the right User for you "); if (Choice.IndexOfChoice == -1) { return(null); } return(UsersList[Choice.IndexOfChoice]);; }
public Message ShowMessages(bool Sent) { List <Message> Messages = DB.GetUserMessages(LoggedIn, IsUserSender: Sent).ToList(); UserChoice Choice = ConsoleMenu.GetUserChoice(Messages.Select(msg => msg.Subject).ToList(), "Choose the message you wanna see"); if (Choice.IndexOfChoice == -1) { return(null); } Message SelectedMessage = Messages[Choice.IndexOfChoice]; Console.WriteLine(SelectedMessage); Console.WriteLine("Press any key to continue"); Console.ReadKey(); return(SelectedMessage); }
public void Update() { User EditedUser; using (var context = new IMEntities()) { List <User> AllUsers = context.Users.ToList(); UserChoice Choice = ConsoleMenu.GetUserChoice(AllUsers.Select(user => user.Username).ToList(), "Choose the user you wanna edit"); EditedUser = AllUsers[Choice.IndexOfChoice]; } List <string> UpdateMenuOptions = new List <string> { "Edit Role", "Edit Username", "Edit Password" }; int option = ConsoleMenu.GetUserChoice(UpdateMenuOptions, DesignedStrings.UpdateUserMenu).IndexOfChoice; switch (option) { case 0: UpdateRole(EditedUser); break; case 1: UpdateUsername(EditedUser); break; case 2: UpdatePassword(EditedUser); break; } Console.ReadKey(); }