public Message GetAnyWantedMessage()
        {
            string AnyMessage = MenuStyle.Horizontal(new List <string> {
                "All Messages", "Back"
            });
            List <Message> Messages = new List <Message>();

            switch (AnyMessage)
            {
            case "All Messages":
                Messages = GetAllMessages();
                break;

            default:
                return(null);
            }
            if (Messages.Count > 0)
            {
                string SelectedMessage = MenuStyle.Vertical(Messages.Select(m => "Message ID: " + m.Id.ToString() + ", at: " + $"{m.TimeSent.ToShortDateString()}" + $", {m.Sender.UserName} " + "sent: " + m.Body + ", to " + $"{m.Receiver.UserName}").ToList());
                return(Messages.Single(pm => "Message ID: " + pm.Id.ToString() + ", at: " + $"{pm.TimeSent.ToShortDateString()}" + $", {pm.Sender.UserName} " + "sent: " + pm.Body + ", to " + $"{pm.Receiver.UserName}" == SelectedMessage));
            }
            else
            {
                Console.WriteLine("No Messages to Display");
                Thread.Sleep(1600);
                return(null);
            }
        }
예제 #2
0
        public void DeleteUser()
        {
            User SelectedUser = MainMenu.SelectUser();

            if (SelectedUser != null)
            {
                string Selection = MenuStyle.Horizontal(new List <string>
                {
                    "Delete User",
                    "Back"
                });

                switch (Selection)
                {
                case "Delete User":
                    DataProvider.DeleteUser(SelectedUser);
                    Console.WriteLine($"{SelectedUser.UserName} just deleted");
                    Thread.Sleep(1600);
                    break;

                case "Back":
                    return;
                }
            }
            else
            {
                return;
            }
        }
        public void ManageUserMenu()
        {
            while (true)
            {
                string AdminSelection = MenuStyle.Vertical(new List <string>
                {
                    "Create User",
                    "Update User Access",
                    "Delete User",
                    "Back"
                });
                switch (AdminSelection)
                {
                case "Create User":
                    mu.CreateUser();
                    break;

                case "Update User Access":
                    mu.UpdateUserAccess();
                    break;

                case "Delete User":
                    mu.DeleteUser();
                    break;

                default:
                    return;
                }
            }
        }
        public User SignInOrRegister(IDataHandling DataProvider)
        {
            string UsersChoice = MenuStyle.Horizontal(new List <string> {
                "Sign In", "Register", "Exit"
            });

            if (UsersChoice == "Exit")
            {
                Console.WriteLine("\tThank you for watching");
                Thread.Sleep(1600);
                Environment.Exit(0);
            }
            else if (UsersChoice == "Register")
            {
                FileStorage file    = new FileStorage();
                UserData    Data    = GetInputUserData(true);
                User        NewUser = new User()
                {
                    UserName   = Data.InputName,
                    Password   = Data.InputPassword,
                    UserAccess = DataProvider.EmptyStorage() ? Role.administrator : Role.visitor
                };
                DataProvider.CreateUserData(NewUser);
                file.CreateFileUserData(NewUser);
                Console.WriteLine($"\nNew User {NewUser.UserName} was created successfully");
                Thread.Sleep(1600);
                return(NewUser);
            }
            else if (UsersChoice == "Sign In")
            {
                tries = 3;
                do
                {
                    User ActiveUser = SigninUser();
                    if (ActiveUser == null)
                    {
                        Console.WriteLine("\nInvalid Username or Password, Please try again");
                        tries--;
                        Console.WriteLine($"Remaining Tries {tries}/3");
                    }
                    else
                    {
                        Console.WriteLine($"\nWelcome { ActiveUser.UserName } !!!");
                        Thread.Sleep(1600);
                        return(ActiveUser);
                    }
                    if (tries == 0)
                    {
                        Console.WriteLine("\nToo many false attempts\n\nExit from application");
                        Thread.Sleep(1800);
                        Environment.Exit(0);
                    }
                }while (true);
            }
            return(null);
        }
        public void MessagesMenu()
        {
            while (true)
            {
                string Choice = MenuStyle.Vertical(new List <string>
                {
                    "Create Message",
                    "Inbox",
                    "View Sent",
                    "Show All Messages",
                    "Edit Message",
                    "Delete Message",
                    "Back"
                });

                switch (Choice)
                {
                case "Create Message":
                    PersonalMessage.CreateMessage();
                    break;

                case "Inbox":
                    PersonalMessage.ShowReceivedMessages();
                    break;

                case "View Sent":
                    PersonalMessage.ShowSentMessages();
                    break;

                case "Show All Messages":
                    PersonalMessage.ShowAllMessages();
                    break;

                case "Edit Message":
                    PersonalMessage.UpdateMessage();
                    break;

                case "Delete Message":
                    PersonalMessage.DeleteMessage();
                    break;

                case "Back":
                    return;
                }
            }
        }
        public static User SelectUser()
        {
            List <User>   UsersList    = DataProvider.ReadUserData();
            List <string> UsernameList = UsersList
                                         .Where(user => user.Id != ActiveUser.Id)
                                         .Select(UserInList => UserInList.UserName)
                                         .ToList();

            if (UsernameList.Count > 0)
            {
                string SelectedUsername = MenuStyle.Vertical(UsernameList);
                return(UsersList.Single(UserOfList => SelectedUsername == UserOfList.UserName));
            }
            else
            {
                Console.WriteLine("No Users to Display");
                Thread.Sleep(1600);
                return(null);
            }
        }
예제 #7
0
        public void UpdateUserAccess()
        {
            User SelectedUser = MainMenu.SelectUser();

            if (SelectedUser != null)
            {
                string UpdateSelection = MenuStyle.Horizontal(new List <string> {
                    $"\n\t{SelectedUser.UserName} is {SelectedUser.UserAccess}, how do you want to change his permissions?"
                });
                if (SelectedUser.UserAccess == Role.administrator)
                {
                    UpdateSelection = MenuStyle.Horizontal(new List <string> {
                        "Downgrade to Moderator", "Downgrade to User", "Downgrade to Visitor", "Back"
                    });
                }
                else if (SelectedUser.UserAccess == Role.moderator)
                {
                    UpdateSelection = MenuStyle.Horizontal(new List <string> {
                        "Upgrade to Administrator", "Downgrade to User", "Downgrade to Visitor", "Back"
                    });
                }
                else if (SelectedUser.UserAccess == Role.user)
                {
                    UpdateSelection = MenuStyle.Horizontal(new List <string> {
                        "Upgrade to Administrator", "Upgrade to Moderator", "Downgrade to Visitor", "Back"
                    });
                }
                else
                {
                    UpdateSelection = MenuStyle.Horizontal(new List <string> {
                        "Upgrade to Administrator", "Upgrade to Moderator", "Upgrade to User", "Back"
                    });
                }

                if (UpdateSelection.Contains("Administrator"))
                {
                    SelectedUser.UserAccess = Role.administrator;
                }
                else if (UpdateSelection.Contains("Moderator"))
                {
                    SelectedUser.UserAccess = Role.moderator;
                }
                else if (UpdateSelection.Contains("User"))
                {
                    SelectedUser.UserAccess = Role.user;
                }
                else if (UpdateSelection.Contains("Visitor"))
                {
                    SelectedUser.UserAccess = Role.visitor;
                }
                else
                {
                    return;
                }
                Console.WriteLine($"{SelectedUser.UserName} updated to {SelectedUser.UserAccess}");
                Thread.Sleep(1700);
                DataProvider.UpdateUserRole(SelectedUser);
            }
            else
            {
                return;
            }
        }
        public void ShowMenu()
        {
            if (ActiveUser != null)
            {
                MessageActions View        = new MessageActions(DataProvider, ActiveUser);
                SignInRegister InitialMenu = new SignInRegister(DataProvider);
                SpecificMenu   MenuActions = new SpecificMenu(DataProvider, ActiveUser);
                while (true)
                {
                    string selecteditem = string.Empty;

                    switch (ActiveUser.UserAccess)
                    {
                    case Role.visitor:
                        selecteditem = MenuStyle.Vertical(new List <string> {
                            "Create Message", "Inbox", "View Sent", "Log Out", "Exit"
                        });
                        break;

                    case Role.user:
                        selecteditem = MenuStyle.Vertical(new List <string> {
                            "Create Message", "Inbox", "View Sent", "Edit Message", "Delete Message", "Log Out", "Exit"
                        });
                        break;

                    case Role.moderator:
                        selecteditem = MenuStyle.Vertical(new List <string> {
                            "Messages", "Log Out", "Exit"
                        });
                        break;

                    case Role.administrator:
                        selecteditem = MenuStyle.Vertical(new List <string> {
                            "Manage Users", "Messages", "Log Out", "Exit"
                        });
                        break;
                    }
                    switch (selecteditem)
                    {
                    case "Manage Users":
                        MenuActions.ManageUserMenu();
                        break;

                    case "Messages":
                        MenuActions.MessagesMenu();
                        break;

                    case "Create Message":
                        View.CreateMessage();
                        break;

                    case "Inbox":
                        View.ShowReceivedMessages();
                        break;

                    case "View Sent":
                        View.ShowSentMessages();
                        break;

                    case "Edit Message":
                        View.UpdateMessage();
                        break;

                    case "Delete Message":
                        View.DeleteMessage();
                        break;

                    case "Log Out":
                        return;

                    case "Exit":
                        Console.WriteLine("\tThank you for watching");
                        Thread.Sleep(1600);
                        Environment.Exit(0);
                        break;
                    }
                }
            }
        }