Exemple #1
0
        void ValidateAndSubmitLogin()
        {
            var dbModel = new UserModelContainer();

            {
                foreach (var user in dbModel.Users)
                {
                    if (textBox_password.Text != "" && textBox_username.Text != "" &&
                        user.Username == textBox_username.Text && user.Password == textBox_password.Text)
                    {
                        label_loginErrorMessage.Text = "";

                        MainPage mainPage = new MainPage();
                        mainPage.Activate();
                        mainPage.ShowDialog();

                        this.Dispose();
                        this.Close();
                    }
                    else
                    {
                        label_loginErrorMessage.Text = "Invalid credentials!";
                    }
                }
            }
        }
Exemple #2
0
        void ValidateAndSubmitUserData()
        {
            User user = new User();

            user.FName    = this.textBox_FName.Text;
            user.LName    = this.textBox_LName.Text;
            user.Username = this.textBox_username.Text;

            if (textBox_createPassword.Text == textBox_confirmPassword.Text &&
                (textBox_createPassword.Text != "" || textBox_confirmPassword.Text != "" || textBox_FName.Text != "" || textBox_LName.Text != "" || textBox_username.Text != ""))
            {
                user.Password = this.textBox_confirmPassword.Text;
                //Using an instance the database model which is stored in UserModel.Context.cs
                using (var dbModel = new UserModelContainer())
                {
                    dbModel.Users.Add(user);
                    try
                    { //Remove exception handling if issue does not persist
                        dbModel.SaveChanges();
                    }
                    catch (DbEntityValidationException ee)
                    {
                        Console.Write(ee);
                    }
                }

                this.Dispose();
                this.Close();
            }
            else if (textBox_createPassword.Text != textBox_confirmPassword.Text)
            {
                label_message.Text = "Passwords do not match. Please try again";
            }
            else if (textBox_FName.Text == "" || textBox_LName.Text == "" || textBox_username.Text == "" ||
                     textBox_createPassword.Text == "" || textBox_confirmPassword.Text == "")
            {
                label_message.Text = "Please fill out empty fields";
            }
        }