private void btnSignUp_Click(object sender, EventArgs e) { using (var ctx = new UsersContext()) { var login = MetaBackEnd.getCorrectLogin(tbLogin.Text); var rawpass = MetaBackEnd.getCorrectLogin(tbPass.Text); var birthDate = dtpBirthDate.Value; var signUpDate = DateTime.Now; var idSpecial = ctx.specials.SingleOrDefault(spec => tbSpecial.Text == spec.special_code).id; var bsalt = MetaBackEnd.GenerateSalt(); var bpass = MetaBackEnd.CalcHash(rawpass, bsalt); var newUser = new awp_users { gender = genderName, login_ = login, password = bpass, birth_date = birthDate, signup_date = signUpDate, salt = bsalt, id_special = idSpecial }; ctx.awp_users.Add(newUser); ctx.SaveChanges(); } }
private void CheckLogin(DataGridViewCell cell) { //Here is login cheking i if (!loginRegex.IsMatch(MetaBackEnd.getCorrectLogin(cell.Value as string))) { cell.ErrorText = "Login должен состоять из 6 to 50 letters of 'А-Яа-я0-9A-Za-z' and space"; isLoginValid = false; } else { using (var ctx = new UsersContext()) { var user = ctx.awp_users.SingleOrDefault(us => us.login_.ToLower() == ((string)cell.Value).ToLower()); if (user != default) { cell.ErrorText = "Login is already used"; isLoginValid = false; } else { cell.ErrorText = ""; isLoginValid = true; } } } SyncBtnSignUpState(); }
private void tbLogin_TextChanged(object sender, EventArgs e) { if (!loginRegex.IsMatch(MetaBackEnd.getCorrectLogin(tbLogin.Text))) { errorSign.SetError(tbLogin, "Login должен состоять из 6 to 50 letters of 'А-Яа-я0-9A-Za-z' and space"); isLoginValid = false; return; } using (var ctx = new UsersContext()) { var user = ctx.awp_users.SingleOrDefault(us => us.login_.ToLower() == tbLogin.Text.ToLower()); if (user != default) { errorSign.SetError(tbLogin, "Login is already used"); isLoginValid = false; } else { errorSign.SetError(tbLogin, ""); isLoginValid = true; } } }