public void EditMessage()
        {
            Message SelectedMessage = ChooseSentOrReceived();

            if (SelectedMessage is null)
            {
                Console.WriteLine("There are NO MESSAGES HERE!\nOK");
                Console.ReadKey();
                return;
            }

            Console.WriteLine(SelectedMessage);
            Console.WriteLine("You want to edit the message?");

            List <string> YesorNoOptions = new List <string>
            {
                "Yes",
                "No"
            };

            int option = ConsoleMenu.GetUserChoice(YesorNoOptions, DesignedStrings.Messagestring).IndexOfChoice;

            switch (option)
            {
            case 0:
                DB.UpdateMessage(Updatedmessage: SelectedMessage);
                break;

            case 1:
                return;
            }

            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
        }
        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 void DeleteMessage(MenuManager menu)
        {
            List <string> DeleteMenuOptions = new List <string>
            {
                "Delete All",
                "Delete From Recieved",
                "Delete From Sent",
            };

            int option = ConsoleMenu.GetUserChoice(DeleteMenuOptions, DesignedStrings.DeleteMsg).IndexOfChoice;

            using (var context = new IMEntities())
            {
                if (option > 0)
                {
                    Message ToDelete = menu.ShowMessages(option > 1);

                    context.Messages.Attach(ToDelete);
                    context.Messages.Remove(ToDelete);
                    context.SaveChanges();
                }
                else
                {
                    Console.WriteLine("\n\n\tWARNING!!!\n\n\tAre you sure you would like to delete EVERYTHING???");
                    Console.ReadKey();
                    context.Messages.RemoveRange(context.Messages
                                                 .Where(msg => msg.SenderId == LoggedIn.Id || msg.RecieverId == LoggedIn.Id));
                    context.SaveChanges();
                }
            }
        }
        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 UpdateRole(User ToChange)
        {
            using (var context = new IMEntities())
            {
                Console.WriteLine("\n\n\n\n\tNew Role: ");

                User WithnewRole = context.Users.Single(ThisUser => ThisUser.Id == ToChange.Id);
                WithnewRole.Role = (UserAccess)ConsoleMenu.GetUserChoice(new List <string> {
                    "Super Admin", "Moderator", "User"
                }).IndexOfChoice;
                context.Entry(WithnewRole).State = EntityState.Modified;
                context.SaveChanges();
                Console.WriteLine($"New User Role is: {WithnewRole.Role}");
                Console.WriteLine("Role Updated Succesfully \n Press any key to continue");
                Console.ReadKey();
            }
        }
        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();
        }
        public void ViewAllUsers()
        {
            List <string> ViewMenuOptions = new List <string>
            {
                "View Usernames",
                "View Usernames & Date of Registration",
                "View Usernames & UserIDs",
                "View Usernames + Passwords",
                "View Usernames & Roles"
            };

            int option = ConsoleMenu.GetUserChoice(ViewMenuOptions, DesignedStrings.ViewUsr).IndexOfChoice;

            switch (option)
            {
            case 0:
                ShowUsernames();
                break;

            case 1:
                ShowUsernameDate();
                break;

            case 2:
                ShowUserIds();
                break;

            case 3:
                ShowUserPass();
                break;

            case 4:
                ShowUserRole();
                break;
            }
        }
        static void Main(string[] args)
        {
            UserReception UF = new UserReception();

            while (true)
            {
                Console.Clear();

                Console.WriteLine("Choose an option");

                List <string> RegisterMenuOptions = new List <string>
                {
                    "Register",
                    "Login",
                    "Terminate the Program"
                };

                int option = ConsoleMenu.GetUserChoice(RegisterMenuOptions, DesignedStrings.DemoMessenger).IndexOfChoice;

                switch (option)
                {
                case 0:
                    UF.RegisterUser();
                    break;

                case 1:
                    UF.LoginUser();
                    break;

                case 2:
                    Console.WriteLine("Thank you for choosing us for your communication needs.");
                    Console.WriteLine("The program will now terminate.");
                    return;
                }
            }
        }
        public void ManagerMenu()
        {
            while (true)
            {
                List <string> MainMenuOptions = new List <string>
                {
                    // "View users"
                    // "Add  User"
                    // "Delete User"
                    // "Update user"
                    // "Edit Message"
                    VIEW_PROFILE,//case 5
                    EDIT_USERNAME,
                    EDIT_PASSWORD,
                    SEND_MESSAGE,
                    VIEW_MESSAGES,//Case 9
                    DELETE_MESSAGE,
                    LOG_OUT,
                    EXIT
                };

                if (LoggedIn.Role == UserAccess.Moderator)
                {
                    MainMenuOptions.Insert(0, ASSIGN_ROLE);
                    // TODO
                }
                else if (LoggedIn.Role == UserAccess.SuperAdministrator)
                {
                    MainMenuOptions.Insert(0, VIEW_USERS);
                    MainMenuOptions.Insert(1, ADD_USER);
                    MainMenuOptions.Insert(2, DELETE_USER);
                    MainMenuOptions.Insert(3, UPDATE_USER);
                    MainMenuOptions.Insert(4, EDIT_MESSAGE);
                }

                string option = ConsoleMenu.GetUserChoice(MainMenuOptions, DesignedStrings.DemoMessenger).NameOfChoice;

                switch (option)
                {
                case VIEW_USERS:
                    UF.ViewAllUsers();
                    break;

                case ADD_USER:
                    Console.WriteLine("\n\nGive Username");
                    string Username = Console.ReadLine();

                    Console.WriteLine("\n\nGive Password");
                    string Password = Console.ReadLine();

                    UF.AddUser(Username, Password);
                    break;

                case DELETE_USER:
                    Console.Clear();
                    UF.DeleteUser(LoggedIn.Id);
                    break;

                case UPDATE_USER:
                    DB.Update();
                    break;

                case EDIT_MESSAGE:
                    EditMessage();
                    break;

                case VIEW_PROFILE:
                    UF.ViewProfile();
                    break;

                case EDIT_USERNAME:
                    DB.UpdateUsername(LoggedIn);
                    break;

                case EDIT_PASSWORD:
                    DB.UpdatePassword(LoggedIn);
                    break;

                case VIEW_MESSAGES:
                    ChooseSentOrReceived();
                    break;

                case SEND_MESSAGE:
                    MessageSend(LoggedIn);
                    break;

                case DELETE_MESSAGE:
                    DB.DeleteMessage(this);
                    break;

                case LOG_OUT:
                    return;

                case EXIT:
                    Console.WriteLine("Thank you for choosing us for your communication needs.");
                    Console.WriteLine("The program will now terminate.");
                    Environment.Exit(0);
                    break;
                }
            }
        }
 public Message ChooseSentOrReceived()
 {
     return(ShowMessages(ConsoleMenu.GetUserChoice(new List <string> {
         "Sent", "Received"
     }).IndexOfChoice == 0));
 }