Exemplo n.º 1
0
        public void EndTest()
        {
            MessageBox.Show("You answered correctly : " + correctQuestionsCount + " of " + selectedTest.Questions.Count);

            TestResult result = new TestResult();
            var        list   = dataBase.Users.Where(x => x.UserName == us.UserName).ToList();

            result.User     = dataBase.Users.Where(x => x.UserName == us.UserName).First();
            result.result   = correctQuestionsCount.ToString() + "/" + selectedTest.Questions.Count.ToString();
            result.testName = selectedTest.TestName;
            dataBase.TestResults.Add(result);
            dataBase.SaveChanges();
            testPanel.Hide();
        }
        private void registerButton_Click(object sender, EventArgs e)
        {
            if (userNameTextBox.Text != "" && passworTextBox.Text != "" && confirmPasswordTextBox.Text != "")
            {
                if (!Regex.IsMatch(userNameTextBox.Text, @"[^A-Za-z0-9_]"))
                {
                    foreach (var users in db.Users)
                    {
                        if (users.UserName == userNameTextBox.Text)
                        {
                            MessageBox.Show("User with this username already exists");
                            return;
                        }
                    }
                    int newUserId = (from p in db.Users
                                     select p).Count();


                    User newUser = new User()
                    {
                        UserName = userNameTextBox.Text,
                        Password = passworTextBox.Text,
                        Id       = newUserId,
                        IsAdmin  = (adminCodeTextBox.Text == adminCode.ToString()) ? true : false
                    };
                    db.Users.Add(newUser);
                    db.SaveChanges();
                    MessageBox.Show("New user is added");

                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Incorrect UserName! You can use A-Z, a-z, 0-9 or '_'");
                }
            }
        }