예제 #1
0
        private void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            if (isRegister)
            {
                if (NameTextbox.Text.Equals("") || SurnameTextbox.Text.Equals("") || PhoneTextbox.Text.Equals("") || UsernameTextbox.Text.Equals("") || PasswordTextbox.Password.Equals("") || MailTextbox.Text.Equals(""))
                {
                    Message msg = new Message("Missing data");
                    msg.ShowDialog();
                    return;
                }

                Hashing      hashing      = new Hashing();
                Users        user         = new Users();
                PersonalData personalData = new PersonalData();
                long         personalId   = 0;

                personalData.name         = NameTextbox.Text;
                personalData.surname      = SurnameTextbox.Text;
                personalData.phone_number = long.Parse(PhoneTextbox.Text);

                bool validatedPersonal = validatePersonalData(personalData);
                if (validatedPersonal)
                {
                    personalId = registerService.createPersonalData(personalData);
                }

                user.username    = UsernameTextbox.Text;
                user.create_date = DateTime.Now;
                user.email_addr  = MailTextbox.Text;
                user.salt        = hashing.CreateSalt(10);
                user.password    = hashing.GenerateHash(PasswordTextbox.Password, user.salt);
                user.personal_id = personalId;

                user.acc_type = IsRenterCheckbox.IsChecked == true ? "R" : "C";

                if (validatedPersonal && validateUserData(user))
                {
                    registerService.createUser(user);
                }

                this.Close();
            }
            else
            {
                PersonalData personalData = new PersonalData();
                personalData.id           = this.id;
                personalData.name         = NameTextbox.Text;
                personalData.surname      = SurnameTextbox.Text;
                personalData.phone_number = long.Parse(PhoneTextbox.Text);
                Users user = new Users();
                user.username   = UsernameTextbox.Text;
                user.acc_type   = IsRenterCheckbox.IsChecked == true ? "R" : "C";
                user.email_addr = MailTextbox.Text;

                if (validatePersonalData(personalData) && validateUserData(user))
                {
                    registerService.updateUser(user);
                    registerService.updatePersonalData(personalData);
                }

                this.Close();
            }
        }