Beispiel #1
0
        public string functionSwitch(string message)
        {
            string tutorial;
            string function;
            string id;
            string password;
            string[] inMessage = message.Split(';');

            function = inMessage[0];

            switch (function)
            {
                case "authenticate":
                    //Console.WriteLine("ATTEMPTING TO AUTHENTICATE SWITCH IS WORKING");
                    //Console.WriteLine("SendingMEssageBacktoClient");

                    //functionMessage = validate(id, password);

                    //outBuff = Encoding.ASCII.GetBytes(functionMessage);

                    //stream.Write(outBuff, 0, functionMessage.Length);
                    //stream.Flush();
                    id = inMessage[1];
                    password = inMessage[2];

                    DBCon authenticate_DB = new DBCon();
                    user u = new user();

                    u.username = id;
                    u.userPW = password;

                    if (authenticate_DB.authenticateUser(u) == true)
                    {
                        return "User has been authenticated.";
                    }
                    else
                    {
                        return "Username or password is incorrect.";
                    }

                case "getAllTutorials":
                    string allTutes = "tutorialList." + getTutorials();
                    return allTutes;
                    //Console.WriteLine(getTutes.getStudentUsername(t));

                case "getStudentSession":
                    id = inMessage[1];
                    password = inMessage[2];
                    string sessionNumber = "studentSessionRequest." + getSessionNumber(id);
                    return sessionNumber;
                case "changeTutorial":
                    string confirmation;
                    id = inMessage[1];
                    tutorial = inMessage[2];
                    DBCon changeTut = new DBCon();
                    user changeTutorialStudent = new user();

                    changeTutorialStudent.username = id;
                    changeTutorialStudent.Session = int.Parse(tutorial);
                    //changeTutorialStudent.userPW = "LOL";
                    confirmation = changeTut.changeSession(changeTutorialStudent);
                    confirmation += ".";

                    //DatabaseHandler dt = new DatabaseHandler();
                    //dt.updateSession(changeTutorialStudent);
                    //Console.WriteLine("MAYBE");
                    return confirmation;
                case "requestStudentsInTutorial":
                    string list = "TutorialStudents.";
                    id = inMessage[1];
                    tutorial = inMessage[2];

                    list += requestStudentsInTutorial(tutorial);

                    return list;
                case "removeStudent":
                    string confirm = "Student removed from tutorial";
                    Console.WriteLine(inMessage);
                    id = inMessage[1];
                    tutorial = inMessage[2];
                    DBCon dbc = new DBCon();
                    user removedStudent = new user();

                    removedStudent.username = id;
                    removedStudent.Session = 0;

                    confirmation = dbc.changeSession(removedStudent);
                    confirmation += ".";

                    return confirm;
                case "findStudent":
                    string studentFound = "foundStudent.";
                    studentFound += getUsers_Details(inMessage[1]);
                    return studentFound;
                case "requestStudentsName":
                    string studentName = "foundStudentName.";
                    string userName = inMessage[1];
                    studentName += getName(userName);

                        return studentName;
                default:
                    return "HUH";
            }
        }
Beispiel #2
0
        public string functionSwitch(string message)
        {
            string tutorial;
            string function;
            string id;
            string password;

            string[] inMessage = message.Split(';');


            function = inMessage[0];



            switch (function)
            {
            case "authenticate":
                //Console.WriteLine("ATTEMPTING TO AUTHENTICATE SWITCH IS WORKING");
                //Console.WriteLine("SendingMEssageBacktoClient");

                //functionMessage = validate(id, password);

                //outBuff = Encoding.ASCII.GetBytes(functionMessage);

                //stream.Write(outBuff, 0, functionMessage.Length);
                //stream.Flush();
                id       = inMessage[1];
                password = inMessage[2];

                DBCon authenticate_DB = new DBCon();
                user  u = new user();

                u.username = id;
                u.userPW   = password;



                if (authenticate_DB.authenticateUser(u) == true)
                {
                    return("User has been authenticated.");
                }
                else
                {
                    return("Username or password is incorrect.");
                }

            case "getAllTutorials":
                string allTutes = "tutorialList." + getTutorials();
                return(allTutes);

            //Console.WriteLine(getTutes.getStudentUsername(t));

            case "getStudentSession":
                id       = inMessage[1];
                password = inMessage[2];
                string sessionNumber = "studentSessionRequest." + getSessionNumber(id);
                return(sessionNumber);

            case "changeTutorial":
                string confirmation;
                id       = inMessage[1];
                tutorial = inMessage[2];
                DBCon changeTut             = new DBCon();
                user  changeTutorialStudent = new user();

                changeTutorialStudent.username = id;
                changeTutorialStudent.Session  = int.Parse(tutorial);
                //changeTutorialStudent.userPW = "LOL";
                confirmation  = changeTut.changeSession(changeTutorialStudent);
                confirmation += ".";


                //DatabaseHandler dt = new DatabaseHandler();
                //dt.updateSession(changeTutorialStudent);
                //Console.WriteLine("MAYBE");
                return(confirmation);

            case "requestStudentsInTutorial":
                string list = "TutorialStudents.";
                id       = inMessage[1];
                tutorial = inMessage[2];

                list += requestStudentsInTutorial(tutorial);

                return(list);

            case "removeStudent":
                string confirm = "Student removed from tutorial";
                Console.WriteLine(inMessage);
                id       = inMessage[1];
                tutorial = inMessage[2];
                DBCon dbc            = new DBCon();
                user  removedStudent = new user();

                removedStudent.username = id;
                removedStudent.Session  = 0;

                confirmation  = dbc.changeSession(removedStudent);
                confirmation += ".";

                return(confirm);

            case "findStudent":
                string studentFound = "foundStudent.";
                studentFound += getUsers_Details(inMessage[1]);
                return(studentFound);

            case "requestStudentsName":
                string studentName = "foundStudentName.";
                string userName    = inMessage[1];
                studentName += getName(userName);

                return(studentName);

            default:
                return("HUH");
            }
        }