public void UpdateUser()
        {
            List <string> ListOfPossibleUsers = DataProvider.ReadUsers().Select(u => u.Username).ToList();

            ListOfPossibleUsers.Remove(ActiveUser.Username);
            if (ListOfPossibleUsers.Count == 0)
            {
                Console.WriteLine("No user found");
                Console.ReadKey();
                return;
            }
            else
            {
                ListOfPossibleUsers.Add("Back");
                string      UserToBeUpdated = SelectionMenu.Vertical(ListOfPossibleUsers).NameOfChoice;
                List <User> ListOfAllUsers  = DataProvider.ReadUsers();
                if (UserToBeUpdated == "Back")
                {
                    return;
                }
                else
                {
                    User      selecteduser     = DataProvider.ReadUsers().Single(us => us.Username == UserToBeUpdated);
                    Privilege NewUserPrivilege = (Privilege)SelectionMenu.Vertical(new List <string> {
                        "admin", "user", "guest"
                    }, $"Choose the privileges of {selecteduser.Username}").IndexOfChoice;
                    DataProvider.UpdateUserAccess(selecteduser, NewUserPrivilege);
                }
            }
        }
Exemple #2
0
        public void ShowMenu()
        {
            if (ActiveUser != null)
            {
                while (true)
                {
                    Console.Clear();
                    Console.CursorVisible = false;
                    string selecteditem = "";

                    switch (ActiveUser.UsersPrivilege)
                    {
                    case Privilege.guest:
                        selecteditem = SelectionMenu.Vertical(new List <string> {
                            "Our Space", "Messages", "Log Out", "Exit"
                        }, Headers.MainMenuHeader).NameOfChoice;
                        break;

                    case Privilege.user:
                        selecteditem = SelectionMenu.Vertical(new List <string> {
                            "Manage User", "Our Space", "Messages", "Log Out", "Exit"
                        }, Headers.MainMenuHeader).NameOfChoice;
                        break;

                    case Privilege.admin:
                        selecteditem = SelectionMenu.Vertical(new List <string> {
                            "Manage User", "Our Space", "Messages", "Log Out", "Exit"
                        }, Headers.MainMenuHeader).NameOfChoice;
                        break;
                    }
                    switch (selecteditem)
                    {
                    case "Our Space":
                        SpecificMenuActions.Forum();
                        break;

                    case "Messages":
                        SpecificMenuActions.MessagesMenu(ActiveUser);
                        break;

                    case "Exit":
                        Environment.Exit(0);
                        break;

                    case "Log Out":
                        return;

                    case "Manage User":
                        SpecificMenuActions.ManageUserMenu();
                        break;
                    }
                }
            }
            else
            {
                Console.WriteLine("\nInvalid! Sorry! No Access!");
                Console.ReadKey();
            }
        }
Exemple #3
0
        public void ShowRecievedMessages()
        {
            while (true)
            {
                // Get the messages
                List <PersonalMessage> PersonalMessages = GetRecievedMessages(IsUserSender: false);

                // User select one
                int indexOfSelectedMessage = SelectionMenu.Vertical(PresentPersonalMessages(PersonalMessages)).IndexOfChoice;

                // Mark it as read
                DataProvider.UpdateMessageAsRead(PersonalMessages[indexOfSelectedMessage].PersonalMessageId);

                // Choose action on READ message
                ManageMessage(indexOfSelectedMessage, PersonalMessages);
            }
        }
Exemple #4
0
        private int GetRecieverId()
        {
            List <string> ListOfRecievers = DataProvider.ReadUsers().Select(u => u.Username).ToList();

            ListOfRecievers.Remove(ActiveUser.Username);
            if (ListOfRecievers.Count == 0)
            {
                return(-1);
            }
            else
            {
                string reciever = SelectionMenu.Vertical(ListOfRecievers, "Whom do you want to send your message to?").NameOfChoice;
                Console.CursorVisible = false;
                User userReciever = DataProvider.ReadUsers().SingleOrDefault(u => u.Username == reciever);
                return(userReciever.UserId);
            }
        }
Exemple #5
0
        public void DeleteMessage(bool IsSender)
        {
            List <PersonalMessage> messageList     = DataProvider.ReadPersonalMessages(ActiveUser, IsSender);
            List <string>          MessageTextList = new List <string>();

            foreach (PersonalMessage message in messageList)
            {
                if ((message.SenderID == ActiveUser.UserId && message.IsMessageShownToSender) || (message.RecieverID == ActiveUser.UserId && message.IsMessageShownToReciever))
                {
                    MessageTextList.Add(message.MessageText);
                }
            }
            if (MessageTextList.Count == 0)
            {
                Console.WriteLine("No message found!");
                Console.ReadKey();
                return;
            }
            else
            {
                bool IsUserSender;
                MessageTextList.Add("Back");
                int index = SelectionMenu.Vertical(MessageTextList, "Delete any message").IndexOfChoice;
                if (index == MessageTextList.Count - 1)
                {
                    return;
                }
                else
                {
                    if (messageList[index].SenderID == ActiveUser.UserId)
                    {
                        IsUserSender = true;
                    }
                    else
                    {
                        IsUserSender = false;
                    }
                    DataProvider.DeleteSelectedPersonalMessage(messageList[index], IsUserSender);
                }
            }
        }
Exemple #6
0
        public void ManageUserMenu()
        {
            string actionselected;

            while (true)
            {
                List <string> Options = (ActiveUser.UsersPrivilege == Privilege.admin) ?
                                        new List <string> {
                    DISABLE_USER, UPGRADE_USER, CREATE_USER, SHOW_DETAILS, BACK
                }
                    : new List <string> {
                    SHOW_DETAILS, BACK
                };

                actionselected = SelectionMenu.Vertical(Options).NameOfChoice;
                switch (actionselected)
                {
                case DISABLE_USER:
                    ManageUser.Disable();
                    break;

                case UPGRADE_USER:
                    ManageUser.UpdateUser();
                    break;

                case CREATE_USER:
                    ManageUser.CreateUser();
                    break;

                case SHOW_DETAILS:
                    ManageUser.ShowDetails();
                    break;

                case BACK:
                    return;
                }
            }
        }
Exemple #7
0
        public void MessagesMenu(User ActiveUser)
        {
            string messageselection;

            while (true)
            {
                string RecievedMessages = "Recieved" + PersonalMessageActions.CheckForUnreadMessages();
                messageselection = SelectionMenu.Vertical(new List <string> {
                    SEND_MESSAGE, SENT, RecievedMessages, DELETE_SENT, DELETE_RECIEVED, BACK
                }, Headers.MessageMenuHeader).NameOfChoice;

                if (messageselection == SEND_MESSAGE)
                {
                    PersonalMessageActions.SendPersonalMessage();
                }
                else if (messageselection == SENT)
                {
                    PersonalMessageActions.ShowSent(IsUserSender: true);
                }
                else if (messageselection == RecievedMessages)
                {
                    PersonalMessageActions.ShowRecievedMessages();
                }
                else if (messageselection == DELETE_SENT)
                {
                    PersonalMessageActions.DeleteMessage(IsSender: true);
                }
                else if (messageselection == DELETE_RECIEVED)
                {
                    PersonalMessageActions.DeleteMessage(IsSender: false);
                }
                else
                {
                    return;
                }
            }
        }