Пример #1
0
        // Method to Create Users
        public static void CreateNewUser()
        {
            UserInsertion user = new UserInsertion();

            Console.WriteLine("Enter your FirstName: ");
            user.FirstName = Console.ReadLine();
            Console.WriteLine("Enter your LastName: ");
            user.LastName = Console.ReadLine();
            Console.WriteLine("Enter your UserName: "******"Your UserName already Exists. Please try another: ");
                user.UserName = Console.ReadLine();
                CheckSameUserName(user);
            }

            Console.WriteLine("Enter your Password: "******"Your Password doesn't match. Please try another: ");
                user.Password = Console.ReadLine();
                CheckPasswordExist(user);
            }

            InsertUserToSql(user);
        }
Пример #2
0
        // Method to Log in a User
        public static void UserLogin()
        {
            // Connection with the Database
            string connectionString =
                @"Server = LAPTOP-7FF4UD5B\SQLEXPRESS;Database = afdeDB; Trusted_Connection = True;";
            SqlConnection sqlConnection = new SqlConnection(connectionString);

            using (sqlConnection)
            {
                try
                {
                    // Check if the connection with Database is already open
                    if (sqlConnection.State == ConnectionState.Open)
                    {
                        sqlConnection.Close();
                    }
                    sqlConnection.Open();

                    Console.WriteLine("Enter your UserName: "******"Enter your Password: "******"SELECT ID, UserName, Password FROM UsersInfo WHERE UserName = '******' AND Password = '******'", sqlConnection);
                    SqlDataReader reader   = cmdLogin.ExecuteReader();
                    UserInsertion user     = new UserInsertion();
                    while (reader.Read())
                    {
                        Console.WriteLine("User Logged In Successfully");
                        user.ID       = reader.GetInt32(0);
                        user.UserName = reader.GetString(1);
                        user.Password = reader.GetString(2);
                        Console.WriteLine(user);
                        Thread.Sleep(3000);
                        Console.Clear();
                        LoginMenu.Menu(usernameInserted);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    sqlConnection.Close();
                }
            }
        }
Пример #3
0
        // Validation that the inserted Password Exist
        public static bool CheckPasswordExist(UserInsertion user)
        {
            // Connection with the Database
            string connectionString =
                @"Server = LAPTOP-7FF4UD5B\SQLEXPRESS;Database = afdeDB; Trusted_Connection = True;";
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            var           check         = true;

            using (sqlConnection)
            {
                try
                {
                    // Check if the connection with Database is already open
                    if (sqlConnection.State == ConnectionState.Open)
                    {
                        sqlConnection.Close();
                    }
                    sqlConnection.Open();

                    SqlCommand    cmdSelect = new SqlCommand($"SELECT * FROM UsersInfo WHERE Password LIKE '{user.Password}'", sqlConnection);
                    SqlDataReader reader    = cmdSelect.ExecuteReader();
                    if (reader.Read())
                    {
                        while (reader.Read())
                        {
                            Console.WriteLine("Password doesn't match.");
                            check = true;
                        }
                    }
                    else
                    {
                        check = false;
                    }
                    reader.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    sqlConnection.Close();
                }
            }
            return(check);
        }
Пример #4
0
        // Method to Send the Data to SQL Database
        public static void InsertUserToSql(UserInsertion user)
        {
            // Connection with the Database
            string connectionString =
                @"Server = LAPTOP-7FF4UD5B\SQLEXPRESS;Database = afdeDB; Trusted_Connection = True;";
            SqlConnection sqlConnection = new SqlConnection(connectionString);

            using (sqlConnection)
            {
                try
                {
                    // Check if the connection with Database is already open
                    if (sqlConnection.State == ConnectionState.Open)
                    {
                        sqlConnection.Close();
                    }
                    sqlConnection.Open();

                    SqlCommand cmdInsert    = new SqlCommand($"INSERT INTO UsersInfo(FirstName, LastName, UserName, Password, Role) VALUES('{user.FirstName}', '{user.LastName}', '{user.UserName}', '{user.Password}', '{(int)Role.CommonUser}')", sqlConnection);
                    int        rowsInserted = cmdInsert.ExecuteNonQuery();
                    if (rowsInserted > 0)
                    {
                        Console.WriteLine("Insertion Successful");
                        Console.WriteLine($"{rowsInserted} rows inserted Successfully");
                    }
                    Thread.Sleep(3000);
                    Console.Clear();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    sqlConnection.Close();
                }
            }
        }
Пример #5
0
        // Method for the Main Screen of the program
        public static void Connection()
        {
            var now = DateTime.Now;

            Console.WriteLine($"***** {now.ToLongDateString()} *****\n");
            Console.WriteLine("Press (1) to Sign in.");
            Console.WriteLine("Press (2) to Register a new account.");
            Console.WriteLine("Press (3) to Exit the program.\n");

            int choice = int.Parse(Console.ReadLine());

            Console.WriteLine("\n");

            switch (choice)
            {
            case 3:
                Console.WriteLine("Good Bye !!!");
                Environment.Exit(2);
                break;

            case 2:
                UserInsertion.CreateNewUser();
                Connection();
                break;

            case 1:
                UserInsertion.UserLogin();
                break;

            default:
                Console.WriteLine("Not a legal entry. Try again later !!!");
                Thread.Sleep(3000);
                Console.Clear();
                Connection();
                break;
            }
        }
Пример #6
0
        // Super Admin Menu Selection
        public static void SuperAdminMenu(string user)
        {
            Console.WriteLine("(1) -- Assign a Role to a User.");
            Console.WriteLine("(2) -- View User's Sent Messages.");
            Console.WriteLine("(3) -- View User's Received Messages.");
            Console.WriteLine("(4) -- Create a new User Profile.");
            Console.WriteLine("(5) -- Update a User's Profile.");
            Console.WriteLine("(6) -- Delete a User's Profile.");
            Console.WriteLine("(7) -- Edit an Existing Message.");
            Console.WriteLine("(8) -- Send a new Message.");
            Console.WriteLine("(9) -- View your Sent Messages.");
            Console.WriteLine("(10) -- View your Received Messages.");
            Console.WriteLine("(11) -- Exit the Program.\n");

            int choice = int.Parse(Console.ReadLine());

            Console.WriteLine("\n");

            switch (choice)
            {
            case 11:
                Console.WriteLine("Good Bye !!!");
                Environment.Exit(2);
                break;

            case 10:
                Message.ViewReceivedMessages(user);
                SuperAdminMenu(user);
                break;

            case 9:
                Message.ViewSentMessages(user);
                SuperAdminMenu(user);
                break;

            case 8:
                Message.SendNewMessage(user);
                SuperAdminMenu(user);
                break;

            case 7: Message.EditExistingMessage();
                SuperAdminMenu(user);
                break;

            case 6:
                UserInsertion.DeleteUser();
                SuperAdminMenu(user);
                break;

            case 5:
                UserInsertion.UpdateUser();
                SuperAdminMenu(user);
                break;

            case 4:
                UserInsertion.CreateNewUser();
                SuperAdminMenu(user);
                break;

            case 3:
                Console.WriteLine("Enter UserName to View his Received Messages:");
                string usersNameReceivedMessages = Console.ReadLine();
                Console.WriteLine("\n");
                Message.ViewReceivedMessages(usersNameReceivedMessages);
                SuperAdminMenu(user);
                break;

            case 2:
                Console.WriteLine("Enter UserName to View his Sent Messages:");
                string usersNameSentMessages = Console.ReadLine();
                Console.WriteLine("\n");
                Message.ViewSentMessages(usersNameSentMessages);
                SuperAdminMenu(user);
                break;

            case 1:
                UserInsertion.AssignRoleToUser();
                SuperAdminMenu(user);
                break;

            default:
                Console.WriteLine("Not a legal entry. Try again!!!");
                Thread.Sleep(3000);
                Console.Clear();
                SuperAdminMenu(user);
                break;
            }
        }
Пример #7
0
        // Admin Menu Selection
        public static void AdminMenu(string user)
        {
            Console.WriteLine("(1) -- Create a new User Profile.");
            Console.WriteLine("(2) -- Update a User's Profile.");
            Console.WriteLine("(3) -- Delete a User's Profile.");
            Console.WriteLine("(4) -- Edit an Existing Message.");
            Console.WriteLine("(5) -- Send a new Message.");
            Console.WriteLine("(6) -- View your Sent Messages.");
            Console.WriteLine("(7) -- View your Received Messages.");
            Console.WriteLine("(8) -- Exit the Program.\n");

            int choice = int.Parse(Console.ReadLine());

            Console.WriteLine("\n");

            switch (choice)
            {
            case 8:
                Console.WriteLine("Good Bye !!!");
                Environment.Exit(2);
                break;

            case 7:
                Message.ViewReceivedMessages(user);
                AdminMenu(user);
                break;

            case 6:
                Message.ViewSentMessages(user);
                AdminMenu(user);
                break;

            case 5:
                Message.SendNewMessage(user);
                AdminMenu(user);
                break;

            case 4:
                Message.EditExistingMessage();
                AdminMenu(user);
                break;

            case 3:
                UserInsertion.DeleteUser();
                AdminMenu(user);
                break;

            case 2:
                UserInsertion.UpdateUser();
                AdminMenu(user);
                break;

            case 1:
                UserInsertion.CreateNewUser();
                AdminMenu(user);
                break;

            default:
                Console.WriteLine("Not a legal entry. Try again!!!");
                Thread.Sleep(3000);
                Console.Clear();
                AdminMenu(user);
                break;
            }
        }