Ejemplo n.º 1
0
        public void runMainMenu(string username)
        {
            ListOption listOptions = new ListOption(username);
            string     title       = "Welcome " + username + "!";

            string[] options =
            {
                "show my entries from list",
                "create a list",
                "add an entry to a list",
                "delete a list",
                "delete an entry from a list",
                "exit"
            };

            while (true)
            {
                Console.Clear();

                int switch_on = ValidateChoice.GetNumber(6, title, options);

                switch (switch_on)
                {
                case 1:
                    listOptions.ShowList(username);
                    Console.WriteLine("> Press any key to continue...");
                    Console.ReadLine();
                    Console.Clear();
                    break;

                case 2:
                    listOptions.CreateList();
                    break;

                case 3:
                    listOptions.AddDelUpdate(username, "add");
                    break;

                case 4:
                    listOptions.AddDelUpdate(username, "delete");
                    break;

                case 5:
                    listOptions.AddDelUpdate(username, "update");
                    break;

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

                default:
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public string[] ShowList(string username) // for current user show list, or get list
        {
            var    file          = new MyFileHandler(username);
            string listDirectory = $@"./account_list/{username}/lists";

            string[] lists = file.GetAvailableList(listDirectory);

            if (lists.Length != 0) //check if any list exists
            {
                while (true)
                {
                    int listNumber = ValidateChoice.GetNumber(lists.Length, "Lists created by " + username, lists);

                    if (listNumber == 0) //exit
                    {
                        break;
                    }

                    try
                    {
                        string[] toDoList = File.ReadAllLines($@"{listDirectory}/{lists[listNumber-1]}.txt");
                        if (toDoList.Length == 0)
                        {
                            MenuPrinter.PrintMenu(lists[listNumber - 1] + " List", null, new string[] { "List is empty..." });
                            break;
                        }
                        else
                        {
                            MenuPrinter.PrintMenu(lists[listNumber - 1] + " List", toDoList, null);
                            return(toDoList);
                        }
                    }
                    catch
                    {
                        Console.WriteLine("> The list you gave us does not exist!");
                        Console.ReadKey();
                        Console.Clear();
                        continue;
                    }
                }
            }
            else
            {
                Console.WriteLine("> No List Exists...");
            }
            return(null);
        }
Ejemplo n.º 3
0
        public string runLoginForm()
        {
            bool   logging_in = true;
            string username   = "";
            string title      = "LOGIN";

            string[] options =
            {
                "Login",
                "Register",
                "Recover",
                "Exit"
            };
            while (logging_in)
            {
                Console.Clear();

                int choice = ValidateChoice.GetNumber(4, title, options);

                switch (choice)
                {
                case 1:
                    username = ValidateChoice.GetUserName(title, new string[] { "Please enter your username." });
                    string password;
                    Console.Write("Passowrd> ");
                    password   = Console.ReadLine();
                    logging_in = checkUser(password, username);
                    break;

                case 2:
                    Register register = new Register();
                    register.runRegistrationForm();
                    break;

                case 3:
                    Recovery recovery = new Recovery();
                    recovery.RunRecoveryForm();
                    break;

                case 4:
                    Environment.Exit(0);
                    break;
                }
            }
            return(username);
        }
Ejemplo n.º 4
0
        public void DeleteItem(string path, string username, string list, string[] lists)
        {
            List <string> xLists = new List <string>();

            string[] toDoList = File.ReadAllLines($@"{path}/{list}.txt");

            int item2del = ValidateChoice.GetNumber(toDoList.Length, "Delete item from list", toDoList);

            Console.Write("> ");
            for (int i = 0; i < toDoList.Length; i++)
            {
                if (item2del == i + 1)
                {
                    continue;
                }
                xLists.Add(toDoList[i]);
            }

            try
            {
                File.Delete($@"{path}/{list}.txt");
                File.WriteAllLines($@"{path}/{list}.txt", xLists);
                Console.WriteLine("deleted...");
                Console.ReadKey();
                Console.Clear();
            }
            catch
            {
                Console.WriteLine("> List file is missing...");
                Console.ReadKey();
            }

            //// YOLO

            //for (int i = 0; i < lists.Length; i++) // keep all lines except chosen one
            //{
            //    if (list == lists[i])
            //    {
            //        continue;
            //    }
            //    xLists.Add(lists[i]);
            //}
        }
Ejemplo n.º 5
0
        public void AddDelUpdate(string username, string addDeleteUpdate)
        {
            bool loop = true;

            string[]      pathLists = Directory.GetFiles("./account_list/" + username + "/lists");
            List <string> xList     = new List <string>();

            string[] currentLists = file_handler.GetAvailableList(listDirectory);

            if (currentLists.Length == 0) //check if any list exists
            {
                Console.WriteLine("> No list exists...");
                Console.WriteLine("> Press any key to continue...");

                Console.ReadKey();
            }
            else
            {
                foreach (var path in pathLists)
                {
                    xList.Add(Path.GetFileName(path));
                }

                string[] lists = new string[xList.Count];
                int      x     = 0;
                foreach (var y in xList)
                {
                    lists[x] = xList[x].Substring(0, xList[x].Length - 4);
                    x++;
                }

                string[] textMorph = { "Add item to list", "Delete List", "Delete Item from List" };
                string   textShown = "Error";
                if (addDeleteUpdate == "add")
                {
                    textShown = textMorph[0];
                }
                if (addDeleteUpdate == "delete")
                {
                    textShown = textMorph[1];
                }
                if (addDeleteUpdate == "update")
                {
                    textShown = textMorph[2];
                }

                while (loop)
                {
                    int item = ValidateChoice.GetNumber(lists.Length, textShown, lists);

                    for (int i = 0; i < lists.Length; i++)
                    {
                        if (item == i + 1)
                        {
                            if (addDeleteUpdate == "add")
                            {
                                inputIntercepter("add", $@"{listDirectory}/{lists[i]}.txt");
                            }

                            if (addDeleteUpdate == "delete")
                            {
                                file_handler.DelteFile(listDirectory, username, lists[i], lists);
                            }

                            if (addDeleteUpdate == "update")
                            {
                                file_handler.DeleteItem(listDirectory, username, lists[i], lists);
                            }

                            loop = false;
                            break;
                        }
                    }

                    if (loop)
                    {
                        Console.WriteLine("> It does not exist!");
                        Console.ReadKey();
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void runRegistrationForm()
        {
            string re_password;
            string password;
            string recovery_answer;

            try
            {
                Login login = new Login();

                string   title   = "Registration Form";
                string[] options =
                {
                    "Enter your new username",
                    "Type 'exit' to exit"
                };

                Console.Write("Username: "******"exit")
                {
                    Environment.Exit(0);
                }

                bool not_existing = checkDirectory(xUsername);

                if (not_existing)
                {
                    while (true)
                    {
                        Console.Write("Password: "******"Re-enter password: "******"\nPassword don't match!");
                            Console.ReadLine();
                        }
                        else
                        {
                            int input = ValidateChoice.GetNumber(3, "Pick a recovery question", questions);

                            Console.Write("Answer to question> ");
                            recovery_answer = Console.ReadLine();

                            makeDirectory(xUsername);
                            makeListDirectory(xUsername);
                            savePassword(xUsername, password);
                            saveRecovery(questions[input - 1], xUsername, password);
                            successEntry();
                            break;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("\nUsername already taken...\nExiting...");
                    Console.ReadLine();
                    Console.Clear();
                }
            }
            catch
            {
                Console.WriteLine("\nInvalid input.\nTry again...");
            }
        }