private void btn_add_Click(object sender, RoutedEventArgs e) { string name = txtName.Text; if (name.Equals(string.Empty)) { MessageBox.Show("Name can not be empty!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } string password = pwbPassword.Password; string passwordConfirm = pwbPasswordConfirm.Password; if (!password.Equals(passwordConfirm)) { MessageBox.Show("Password confirm does not match!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } string mail = txtMail.Text; if (mail.Equals(string.Empty)) { MessageBox.Show("Email can not be empty!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } using (MySqlDbContext db = new MySqlDbContext()) { UserRegistered = new User(); UserRegistered.name = name; UserRegistered.password = PasswordProcessor.EncryptPassword(password); UserRegistered.email = mail; UserRegistered.created_at = DateTime.Now; UserRegistered.updated_at = DateTime.Now; UserRegistered.status = "active"; db.Roles.Load(); Role clientRole = db.Roles.FirstOrDefault(r => r.name.Equals("Client")); if (!(clientRole is null)) { UserRegistered.roles.Add(clientRole); } //adding row to db context db.Users.Add(UserRegistered); db.SaveChanges(); this.Close(); } }
private void btn_Login_Click(object sender, RoutedEventArgs e) { string email = txt_Email.Text.ToLower(); User user = null; using (MySqlDbContext db = new MySqlDbContext()) { db.Users.Load(); user = db.Users.FirstOrDefault(u => u.email.ToLower().Equals(email)); } if (!(user is null)) { string password = txt_Password.Password; bool isPasswordCorrect = PasswordProcessor.CheckPasswordsMatch(user.password, password); if (isPasswordCorrect) { MainWindow mainWindow = new MainWindow(user); mainWindow.Show(); this.Close(); } }