private void saveChangesButton_Click(object sender, RoutedEventArgs e) { using (UserContext context = new UserContext()) { if (!Globals.IsUsernameValid(usernameTextBox.Text) && usernameTextBox.Text != "") { informLabel.Content = "Incorrect username!"; } else { context.Users.Find(); } } }
private void confirmButton_Click(object sender, RoutedEventArgs e) { if (!Globals.IsUsernameValid(usernameTextBox.Text) || usernameTextBox.Text == "") { informLabel.Content = "Incorrect username!"; } else if (IsUsernameUsed(usernameTextBox.Text)) { informLabel.Content = "Username is already used!"; } else if (!IsEmailValid(emailTextBox.Text)) { informLabel.Content = "Email is not valid!"; } else if (passwordBox.Password.Length < 8) { informLabel.Content = "Password is too short!"; } else if (!IsDataCorrect(passwordBox.Password)) { informLabel.Content = "Incorrect password!"; } else if (passwordBox.Password != repeatPasswordBox.Password) { informLabel.Content = "Passwords are different!"; } else { using (UserContext context = new UserContext()) { System.Windows.Controls.Image avatar = new System.Windows.Controls.Image(); avatar.Source = new BitmapImage (new Uri(@"C:\Users\Max\Documents\CourseWork\CourseWork\Images\avatar.png")); var user = new User() { Username = usernameTextBox.Text, Email = emailTextBox.Text, Password = passwordBox.Password, Avatar = BitmapSourceToByteArray((BitmapSource)avatar.Source), SumRating = 5, AmountOfVoters = 1, SignedUpEventsID = "0 " }; context.Users.Add(user); context.SaveChanges(); } App.Current.MainWindow.Content = new LoginPage(); } }