public Boolean Registration()
        {
            string cNo;
            int    role;
            string fname;
            string lname;
            string email;
            string password;
            string confirmPass;

            Console.WriteLine("Please Register Below...\n");
            Console.Write("Enter your first Name: ");
            fname = Console.ReadLine();
            while (!Validators.isValidString(fname)) //check if the user entered letters only
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Enter a valid name");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("Enter your first Name: ");
                fname = Console.ReadLine();
            }

            Console.Clear();
            Console.Write("Enter your Last Name: ");
            lname = Console.ReadLine();
            while (!Validators.isValidString(lname))  //check if the user entered letters only
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Enter a valid last name");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("Enter your first Name: ");
                lname = Console.ReadLine();
            }

            Console.Clear();
            Console.Write("Enter your Email Address: ");
            email = Console.ReadLine();

            bool emailInvalid = true;

            do
            {
                bool valid = Validators.isValidEmail(email);
                if (valid)
                {
                    if (Database.Instance.EmailExists(email))
                    {
                        Console.Clear();
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("The email " + email + " already Exists");
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Write("Enter your Email Address: ");
                        email = Console.ReadLine();
                    }
                    else
                    {
                        emailInvalid = false;
                    }
                }
                else
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Please enter a valid email address.");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write("Enter your Email Address: ");
                    email = Console.ReadLine();
                }
            } while(emailInvalid);

            Console.Clear();
            Console.Write("Enter your Phone Number: ");
            cNo = Console.ReadLine();
            while (!Validators.isPhoneNumber(cNo))  //validate if the user enters a valid contact details
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Invalid Contact Details");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("Enter your Phone Number: ");
                cNo = Console.ReadLine();
            }

            role = chooseUserRoleMenu();

            if (role == -1)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Registration cancelled\n");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey(true);
                return(false);
            }

            Console.Clear();
password:
            Console.Write("Enter Password: "******"Password must at least:\n* Be 8 characters long\n* Contain an uppercase and lowercase\n* Contain a number\n* Contain a symbol/special character\n");
                Console.ForegroundColor = ConsoleColor.White;
                goto password;
            }

            Console.Clear();
            Console.Write("Confirm Password: "******"\n\nPassword does not match\n");
                Console.ForegroundColor = ConsoleColor.White;
                goto password;
            }

            User registrationUser = new User(0, fname, lname, email, password, cNo, role);

            if (registerOrCancelMenu(registrationUser) > 0)
            {
                if (Database.Instance.Register(registrationUser))
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Account has been created Successfully\n");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Registration cancelled\n");
                Console.ForegroundColor = ConsoleColor.White;
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);
            return(true);
        }
Exemple #2
0
        public static void ManageProfile()//A method that allow the user to update their inforomation
        {
            string firstName = "";
            string lastName  = "";
            string email     = "";
            string cell      = "";

            bool showMenu = true;
            int  option   = 1;

            //This is a menu that shows what information the user wants to change, i.e. the First Name, Last Name, Email.
            while (showMenu)
            {
                Console.Clear();
                Console.WriteLine("Choose from the following options: ");
                Console.WriteLine("Use Up arrow and Down arrow to move, enter/spacebar to select");
                //The updating first name option
                if (option == 1)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("*  ");
                    Console.Write("Update first name\n");
                    Console.ResetColor();
                }
                else
                {
                    Console.Write("   ");
                    Console.Write("Update first name\n");
                }
                //The updating last name option
                if (option == 2)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("*  ");
                    Console.Write("Update last name\n");
                    Console.ResetColor();
                }
                else
                {
                    Console.Write("   ");
                    Console.Write("Update last name\n");
                }
                //The updating email option
                if (option == 3)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("*  ");
                    Console.Write("Update email\n");
                    Console.ResetColor();
                }
                else
                {
                    Console.Write("   ");
                    Console.Write("Update email\n");
                }
                //The updating cellphone number option
                if (option == 4)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("*  ");
                    Console.Write("Update cellphone number\n");
                    Console.ResetColor();
                }
                else
                {
                    Console.Write("   ");
                    Console.Write("Update cellphone number\n");
                }
                if (option == 5)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("*  ");
                    Console.WriteLine("Exit\n");
                    Console.ResetColor();
                }
                else
                {
                    Console.Write("   ");
                    Console.WriteLine("Exit\n");
                }

                switch (Console.ReadKey().Key)
                {
                case ConsoleKey.UpArrow:

                    if (option != 1)
                    {
                        option--;
                    }
                    Console.Clear();
                    break;

                case ConsoleKey.DownArrow:
                    if (option != 5)
                    {
                        option++;
                    }
                    Console.Clear();
                    break;

                case ConsoleKey.Enter:
                case ConsoleKey.Spacebar:
                    Console.Clear();
                    //The options which allow the user to change/update their information
                    switch (option)
                    {
                    //Update their First Name
                    case 1:
                        Console.WriteLine("**********************************************");
                        Console.WriteLine("You are updating your first name: " + Authenticate.Instance.User.first_name);
                        Console.WriteLine("\nPlease enter the first name you wish to replace it with");
                        firstName = Console.ReadLine();
                        while (string.IsNullOrEmpty(firstName) || string.IsNullOrWhiteSpace(firstName) || firstName == Authenticate.Instance.User.first_name)
                        {
                            Console.Clear();
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("\nFirst name already exists or input is invalid!");
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine("\nPlease enter a valid first name: ");
                            firstName = Console.ReadLine();
                        }
                        Database.Instance.updateProfileField(firstName, UpdateProfileField.FirstName);
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nYour updated name is: " + firstName);
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine("**********************************************");
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey(true);
                        break;

                    //Updating the user Last Name
                    case 2:
                        Console.WriteLine("**********************************************");
                        Console.WriteLine("You are updating your last name: " + Authenticate.Instance.User.last_name);
                        Console.WriteLine("\nPlease enter the name you wish to replace it with");
                        lastName = Console.ReadLine();
                        while (string.IsNullOrEmpty(lastName) || string.IsNullOrWhiteSpace(lastName) || lastName == Authenticate.Instance.User.last_name)
                        {
                            Console.Clear();
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("\nLast name already exists or last name is invalid!");
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine("\nPlease enter a valid last name: ");
                            lastName = Console.ReadLine();
                        }

                        Database.Instance.updateProfileField(lastName, UpdateProfileField.LastName);
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nYour updated last name is: " + lastName);
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine("**********************************************");
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey(true);
                        break;

                    //Updating the email
                    case 3:
                        Console.WriteLine("**********************************************");
                        Console.WriteLine("You are updating your email: " + Authenticate.Instance.User.email);
                        Console.WriteLine("\nPlease enter the email you wish to replace it with");
                        email = Console.ReadLine();

                        while (string.IsNullOrEmpty(email) ||
                               string.IsNullOrWhiteSpace(email) ||
                               email == Authenticate.Instance.User.email ||
                               Database.Instance.EmailExists(email) ||
                               !Validators.isValidEmail(email))
                        {
                            Console.Clear();
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("\nEmail already exists or email is invalid!");
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine("\nPlease enter a valid email: ");
                            email = Console.ReadLine();
                        }

                        Database.Instance.updateProfileField(email, UpdateProfileField.Email);

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nYour updated last email is: " + email);
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine("**********************************************");
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey(true);
                        break;

                    //Updating the cellphone number
                    case 4:
                        Console.WriteLine("**********************************************");
                        Console.WriteLine("You are updating your cell phone number to: " + Authenticate.Instance.User.cellphone_number);
                        Console.WriteLine("\nPlease enter the cellphone number you wish to replace it with");
                        cell = Console.ReadLine();
                        while (Validators.isPhoneNumber(cell) != true)
                        {
                            Console.Clear();
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("\nInvalid Contact Details");
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine("\nEnter your Phone Number: ");
                            cell = Console.ReadLine();
                        }
                        while (string.IsNullOrEmpty(cell) ||
                               string.IsNullOrWhiteSpace(cell) ||
                               cell == Authenticate.Instance.User.cellphone_number ||
                               !Validators.isPhoneNumber(cell))
                        {
                            Console.Clear();
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("\nCellphone number already exists or Cellphone number is invalid!");
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine("\nPlease enter a valid Cellphone number: ");
                            cell = Console.ReadLine();
                        }

                        Database.Instance.updateProfileField(cell, UpdateProfileField.ContactNo);

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nYour updated last cellphone number is: " + Authenticate.Instance.User.cellphone_number);
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine("**********************************************");
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey(true);
                        break;

                    case 5:
                        Console.WriteLine("\nExiting...");
                        showMenu = false;
                        break;
                    }
                    //If the user wants to continue or proceed with other tasks
                    break;

                default:
                    Console.WriteLine("\nInvalid key, use Up/Down arrow to move, enter/spacebar to select");
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey(true);
                    break;
                }
            }
        }
        public Boolean ForgotPassword()
        {
            string confirmNewPass;
            string password;
            string email;
            string cNo;

            Console.Write("Please enter your email address: ");
            email = Console.ReadLine();
            while (!Validators.isValidEmail(email)) //Checking if the user Entered a valid email
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Enter a valid email address.");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("\nEnter your Email Address: ");
                email = Console.ReadLine();
            }

            Console.Write("Please enter your contact details: ");
            cNo = Console.ReadLine();
            while (!Validators.isPhoneNumber(cNo))   //Validate if the user entered valid phone number
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Invalid Contact Details");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("\nEnter your Phone Number: ");
                cNo = Console.ReadLine();
            }

            Console.Clear();
forgotPassword:
            Console.Write("Enter a new password: "******"Password must at least:\n* Be 8 characters long\n* Contain an uppercase and lowercase\n* Contain a number\n* Contain a symbol/special character\n");
                Console.ForegroundColor = ConsoleColor.White;
                goto forgotPassword;
            }

            Console.Clear();
            Console.Write("Confirm Password: "******"\nPassword does not match");
                Console.ForegroundColor = ConsoleColor.White;
                goto forgotPassword;
            }

            if (Database.Instance.updatePassword(email, cNo, confirmNewPass))
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Password has been changed successfully!");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("\nPress any key to continue...");
                Console.ReadKey(true);
            }
            else
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Password failed to be changed...\nTry again or contact manager");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("\nPress any key to continue...");
                Console.ReadKey(true);
            }

            return(true);
        }
        public static Boolean LogIncident()//A method that allows the user to Report their incidents
        {
            //The user is prompted to log the incident which requires them to enter the decrtion and the location of the incident
            Console.WriteLine("**********************************************\n");
            Console.WriteLine("Enter incident description: ");
            string incidentDescription = Console.ReadLine();

            while (string.IsNullOrEmpty(incidentDescription) || string.IsNullOrWhiteSpace(incidentDescription) || !Validators.isValidInputString(incidentDescription))
            {
                Console.WriteLine("Invalid! Please enter valid description: ");
                incidentDescription = Console.ReadLine();
            }

            Console.Clear();
            Console.WriteLine("Enter incident location: ");
            Console.WriteLine("i.e. Gijima Midrand, Gazelle Close, Floor 2, room: Siyabonga");
            string incidentLocation = Console.ReadLine();

            while (string.IsNullOrEmpty(incidentLocation) || string.IsNullOrWhiteSpace(incidentLocation) || !Validators.isValidInputLocString(incidentDescription))
            {
                Console.WriteLine("Invalid! Please enter valid location: ");
                Console.WriteLine("i.e. Gijima Midrand, Gazelle Close, Floor 2, room: Siyabonga");
                incidentLocation = Console.ReadLine();
            }
            DateTime date = DateTime.Now;

            //The input that will be saved in the database
            Incident incident = new Incident(0, incidentLocation, incidentDescription, date, 0, Authenticate.Instance.User, null);

            if (saveOrCancelMenu(incident) > 0)
            {
                if (Database.Instance.LogIncident(incident))
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Incident Successfully\n");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey(true);
                    /// Set timer for escalation
                    IncidentSystem.Instance.setTimerForEscalation(Database.Instance.GetIncidentID(incident), false);
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Incident cancelled\n");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey(true);
            }

            Console.WriteLine("Press any key to continue...");
            Console.Clear();
            // if (Database.Instance.LogIncident(incident)) {
            //     Console.ForegroundColor = ConsoleColor.Green;
            //     Console.WriteLine("Incident Successfully logged!");
            //     Console.WriteLine("\nPress any key to continue...");
            //     Console.ForegroundColor = ConsoleColor.White;

            //     /// Set timer for escalation
            //     IncidentSystem.Instance.setTimerForEscalation(Database.Instance.GetIncidentID(incident), false);
            // } else {
            //     Console.ForegroundColor = ConsoleColor.Red;
            //     Console.WriteLine("An error has occured! Please contact administrator");
            //     Console.WriteLine("\nPress any key to continue...");
            //     Console.ForegroundColor = ConsoleColor.White;
            // }
            Console.ReadKey(true);
            return(true);
        }