Exemple #1
0
        /* -------------------------------- Add User -------------------------------- */
        public void AddUser(User user)
        {
            /// <summary> Add a predefined user to the database
            // Creates and assign values
            PersonTable personTemplate = new PersonTable()
            {
                Name = user.Name
                       // Username = user.Username
            };

            // Add user to the Person table
            AddUserToDatabase(personTemplate);

            int personID = GetIDNonUser(personTemplate.Name);

            Console.WriteLine("Hittade ID");

            // Creates and assign values
            LoginDetailsTable LoginDetailsTemplate = new LoginDetailsTable()
            {
                PersonID = personID,
                Email    = user.Email,
                Username = user.Username,
                Password = user.Password,
                //Phonenumber = user.Phonenumber
            };

            Console.WriteLine("Skapade login details");
            // Add user to the LoginDetails table
            AddUserToDatabase(LoginDetailsTemplate);
            Console.WriteLine("Lade till användare");
        }
Exemple #2
0
        /* -------------------------------- Get Data -------------------------------- */
        public List <LoginDetailsTable> getData(string Username)
        {
            /// <summary> Returns Username, UserPassword, Email, PhoneNumber as a list for the matching Username
            string executeString = string.Format("EXEC SearchForUsername @Username = '******'", Username);
            var    query         = LoginDetailsTable.SendAndGetQuery(executeString);

            return(query.ToList());
        }
Exemple #3
0
        /* --------------------------------- Search --------------------------------- */
        public int GetIDNonUser(string Name)
        {   /// <summary> Returns the ID from users without accounts of the matching Username combination
            string executeString = string.Format("EXEC GetID @PersonName = '{0}'", Name);
            var    query         = LoginDetailsTable.SendAndGetQuery(executeString);

            foreach (var item in query)
            {
                return(item.PersonID);
            }
            return(0);
        }
Exemple #4
0
        public int GetIDExistingUser(string Username)
        {   /// <summary> Returns the ID from users with accounts of the matching Username combination
            string executeString = string.Format("EXEC GetIDFromLogin @Username = '******'", Username);
            var    query         = LoginDetailsTable.SendAndGetQuery(executeString);

            Debug.WriteLine(query);

            foreach (var item in query)
            {
                return(item.PersonID);
            }
            return(0);
        }
Exemple #5
0
        public bool LoginEmail(string Email, string Password)
        {
            /// <summary> Allows login with Email/Password combination
            string executeString = string.Format(
                "SELECT PersonID FROM Student29.dbo.LoginDetails WHERE Email = '{0}' AND Password = '{1}",
                Email,
                Password);
            var query = LoginDetailsTable.SendAndGetQuery(executeString);

            LoginDetailsTable[] queryArray = query.ToArray();

            return(isCorrectCredentials(queryArray));
        }
Exemple #6
0
        /* ---------------------------------- Login --------------------------------- */
        public bool LoginUsername(string Username, string Password)//return bool pls
        {
            /// <summary> Allows login with Username/Password combination
            string executeString = string.Format(
                "SELECT PersonID FROM Student29.dbo.LoginDetails WHERE Username = '******' AND UserPassword = '******'",
                Username,
                Password);
            var query = LoginDetailsTable.SendAndGetQuery(executeString);

            LoginDetailsTable[] queryArray = query.ToArray();

            return(isCorrectCredentials(queryArray));
        }
Exemple #7
0
        private void AddUserToDatabase(LoginDetailsTable loginDetailsTable)
        {
            /// <summary> Add a user to the LoginDetails table
            string executeString = string.Format(
                "INSERT INTO Student29.dbo.LoginDetails VALUES ({0},'{1}','{2}','{3}')",
                loginDetailsTable.PersonID,
                loginDetailsTable.Username,
                loginDetailsTable.Password,
                loginDetailsTable.Email);

            //loginDetailsTable.Phonenumber);
            Debug.WriteLine("Successfully sent: " + executeString);
            LoginDetailsTable.SendQuery(executeString);
        }