private void Submit_Click(object sender, RoutedEventArgs e)
        {
            if (TextBoxEmail.Text.Length == 0)
            {
                Errormessage.Text = "Enter an email.";
                TextBoxEmail.Focus();
            }
            else if (!Regex.IsMatch(TextBoxEmail.Text,
                                    @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
            {
                Errormessage.Text = "Enter a valid email.";
                TextBoxEmail.Select(0, TextBoxEmail.Text.Length);
                TextBoxEmail.Focus();
            }
            else
            {
                string firstname = TextBoxFirstName.Text;
                string lastname  = TextBoxLastName.Text;
                string email     = TextBoxEmail.Text;
                string password  = PasswordBox1.Password;
                if (PasswordBox1.Password.Length == 0)
                {
                    Errormessage.Text = "Enter password.";
                    PasswordBox1.Focus();
                }
                else if (PasswordBoxConfirm.Password.Length == 0)
                {
                    Errormessage.Text = "Enter Confirm password.";
                    PasswordBoxConfirm.Focus();
                }
                else if (PasswordBox1.Password != PasswordBoxConfirm.Password)
                {
                    Errormessage.Text = "Confirm password must be same as password.";
                    PasswordBoxConfirm.Focus();
                }
                else
                {
                    Errormessage.Text = "";
                    User newUser = new User()
                    {
                        Pass             = password,
                        Email            = email,
                        FirstName        = firstname,
                        LastName         = lastname,
                        RegistrationDate = DateTime.Now
                    };


                    if (SaveToDatabase(newUser))
                    {
                        Errormessage.Text = "You have Registered successfully.";
                        RedirectToLoginPage(newUser);
                        Reset();
                    }
                }
            }
        }
Exemple #2
0
        private void ButtonSubmit_Click(object sender, RoutedEventArgs e)
        {
            if (TextBoxEmail.Text.Length == 0)
            {
                ErrorMessage.Text = "Enter an email.";
                TextBoxEmail.Focus();
            }
            else if (!Regex.IsMatch(TextBoxEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
            {
                ErrorMessage.Text = "Enter a valid email.";
                TextBoxEmail.Select(0, TextBoxEmail.Text.Length);
                TextBoxEmail.Focus();
            }
            else
            {
                string firstName = TextBoxFirstName.Text;
                string lastName  = TextBoxLastName.Text;
                string email     = TextBoxEmail.Text;
                string password  = PasswordBox1.Password;
                if (PasswordBox1.Password.Length == 0)
                {
                    ErrorMessage.Text = "Enter password.";
                    PasswordBox1.Focus();
                }
                else if (PasswordBoxConfirm.Password.Length == 0)
                {
                    ErrorMessage.Text = "Enter Confirm password.";
                    PasswordBoxConfirm.Focus();
                }
                else if (PasswordBox1.Password != PasswordBoxConfirm.Password)
                {
                    ErrorMessage.Text = "Confirm password must be same as password.";
                    PasswordBoxConfirm.Focus();
                }
                else
                {
                    ErrorMessage.Text = "";

                    _registerController.CreateNewUser(firstName, lastName, email, password);
                    ErrorMessage.Text = "You have Registered successfully.";
                    Reset();
                    FrameMain.Navigate(new ShowItemsView());
                }
            }
        }