private void logBt_Click(object sender, RoutedEventArgs e) { UserData userData = new UserData(); MessagesData messagesData = new MessagesData(); SetupData(userData); using (registerDbEntities db = new registerDbEntities()) { if (NotEmpty(userData)) { if (LoginValid(userData, db)) { OpenProfile(); } else { msg.Content = messagesData.LoginValid; } } else { msg.Content = messagesData.MsgEmpty; } } }
private void CheckUser(UserData ud, registerDbEntities db, MessagesData messagesData) { foreach (User _user in ud.Users) { if (_user != null) { if (!Validation(ud)) { msg.Content = messagesData.MsgEmpty; } else { if (IsValid(ud.Email)) { if (ud.Password == ud.PassRepeat) { DbUpdate(_user, ud, db); } } else { msg.Content = messagesData.MsgValidEmail; } } } } }
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 bool LoginValid(UserData userData, registerDbEntities db) { var User = db.Users.FirstOrDefault(u => u.nick.Equals(userData.Nick)); if (User != null) { if (userData.Nick == User.nick && userData.Password == User.password) { return(true); } else { return(false); } } else { return(false); } }
private void regBt_Click(object sender, RoutedEventArgs e) { msg.Content = string.Empty; UserData userData = new UserData(); MessagesData messagesData = new MessagesData(); SetupData(userData); DownloadData(userData); using (registerDbEntities db = new registerDbEntities()) { if (NotEmpty(userData)) { AddUser(userData); CheckUser(userData, db, messagesData); } else { msg.Content = messagesData.MsgEmpty; } } }
private void logBt_Click(object sender, RoutedEventArgs e) { UserData ud = new UserData(); ud.Nick = nickTxt.Text; ud.Password = passTxt.Password; ProfileData.Name = nickTxt.Text; using (registerDbEntities db = new registerDbEntities()) { if (ud.Nick != string.Empty || ud.Password != string.Empty) { var login = db.Users.FirstOrDefault(a => a.nick.Equals(ud.Nick)); if (login != null) { if (login.nick.Equals(ud.Nick) && login.password.Equals(ud.Password)) { Profile winProfile = new Profile(); winProfile.WindowStartupLocation = WindowStartupLocation.CenterScreen; winProfile.WindowState = WindowState.Maximized; winProfile.Show(); this.Close(); } else if (nickTxt.Text == string.Empty || passTxt.Password == string.Empty) { MessageBox.Show("Please complete the data"); } else { MessageBox.Show("Login or password is incorrect"); } } else if (nickTxt.Text == string.Empty || passTxt.Password == string.Empty) { MessageBox.Show("Please complete the data"); } else { MessageBox.Show("Login or password is incorrect"); } } else { if (nickTxt.Text == string.Empty || passTxt.Password == string.Empty) { MessageBox.Show("Please complete the data"); } else if (nickTxt.Text == string.Empty && passTxt.Password == string.Empty) { MessageBox.Show("Please complete the data"); } else { MessageBox.Show("Error"); } } } }
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"); } } } } } }