Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void okButton_Click(object sender, EventArgs e)
- {
- var login = loginTextBox.Text.ToLowerInvariant();
- if (string.IsNullOrWhiteSpace(login))
- {
- MessageBox.Show(
- caption: "Error",
- text: "Login cannot be empty.",
- icon: MessageBoxIcon.Error,
- buttons: MessageBoxButtons.OK);
- DialogResult = DialogResult.None;
- return;
- }
- string pass = changePassword ? AuthorizeForm.MD5f(passTextBox.Text) : null;
- if (pass != null)
- {
- if (passConfirmTextBox.Enabled && pass != AuthorizeForm.MD5f(passConfirmTextBox.Text))
- {
- MessageBox.Show(
- caption: "Error",
- text: "Passwords do not match.",
- icon: MessageBoxIcon.Error,
- buttons: MessageBoxButtons.OK);
- DialogResult = DialogResult.None;
- return;
- }
- }
- var add = User == null;
- if (User == null)
- User = new User();
- var db = Context.Instance;
- if (db.Users.Any(u => u.Login == login && (add || u.Id != User.Id)))
- {
- MessageBox.Show(
- caption: "Error",
- text: "User with this login already exists.",
- icon: MessageBoxIcon.Error,
- buttons: MessageBoxButtons.OK);
- DialogResult = DialogResult.None;
- return;
- }
- User.Login = login;
- User.Pass = changePassword ? pass : User.Pass;
- User.IsAdmin = roleCombo.Text == "Teacher";
- if (add)
- db.Users.Add(User);
- db.SaveChanges();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement