Beispiel #1
0
 private void DbUpdate(User _user, UserData ud, registerDbEntities db)
 {
     _user.name        = ud.Name;
     _user.surname     = ud.Surname;
     _user.nick        = ud.Nick;
     _user.email       = ud.Email;
     _user.password    = ud.Password;
     _user.pass_repeat = ud.PassRepeat;
     _user.data_birth  = Convert.ToDateTime(ud.DateBirth);
     db.Users.Add(_user);
     db.SaveChanges();
 }
        private void regBt_Click(object sender, RoutedEventArgs e)
        {
            ud             = new UserData();
            ud.Name        = nameTxt.Text;
            ud.Surname     = surnameTxt.Text;
            ud.Nick        = nickTxt.Text;
            ud.Email       = emailTxt.Text;
            ud.Password    = passbox.Password;
            ud.PassRepeat  = rPassbox.Password;
            ud.DateBirth   = dataBox.Text;
            ud.TypeAccount = accountSelect.Text;

            ProfileData.Name    = ud.Nick;
            ProfileData.Account = ud.TypeAccount;
            SaveData sd = new SaveData();

            sd.DataToSave(ud, "registerData.xml");

            using (db = new registerDbEntities())
            {
                ud.Users = new List <User>();

                if (nameTxt.Text != string.Empty)
                {
                    if (surnameTxt.Text != string.Empty)
                    {
                        if (nickTxt.Text != string.Empty)
                        {
                            if (emailTxt.Text != string.Empty)
                            {
                                if (dataBox.Text != string.Empty)
                                {
                                    if (passbox.Password != string.Empty)
                                    {
                                        if (rPassbox.Password != string.Empty)
                                        {
                                            ud.Users.Add(new User()
                                            {
                                                name        = ud.Name,
                                                surname     = ud.Surname,
                                                nick        = ud.Nick,
                                                email       = ud.Email,
                                                data_birth  = Convert.ToDateTime(ud.DateBirth),
                                                password    = ud.Password,
                                                pass_repeat = ud.PassRepeat
                                            });
                                        }
                                        else
                                        {
                                            MessageBox.Show("Please repeat password");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Password is required");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Date of birth is required");
                                }
                            }
                            else
                            {
                                MessageBox.Show("Email is required");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Nick is required");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Surname is required");
                    }
                }
                else
                {
                    MessageBox.Show("Name is required");
                }
                foreach (var user in ud.Users)
                {
                    if (user != null)
                    {
                        if (!NotEmpty(ud.Name, ud.Surname, ud.Name, ud.Email, ud.DateBirth, ud.Password, ud.PassRepeat))
                        {
                            MessageBox.Show("Please complete all the data");
                        }
                        else
                        {
                            if (IsValid(emailTxt.Text))
                            {
                                if (passbox.Password == rPassbox.Password)
                                {
                                    user.name        = ud.Name;
                                    user.surname     = ud.Surname;
                                    user.nick        = ud.Nick;
                                    user.email       = ud.Email;
                                    user.password    = ud.Password;
                                    user.pass_repeat = ud.PassRepeat;
                                    user.data_birth  = Convert.ToDateTime(ud.DateBirth);
                                    db.Users.Add(user);
                                    db.SaveChanges();
                                }
                            }
                            else
                            {
                                MessageBox.Show("It's not address email");
                            }
                        }
                    }
                }
            }
        }