Beispiel #1
0
        protected void btnAnswer_Click(object sender, EventArgs e)
        {
            int qId = Convert.ToInt32(Request["id"]);

            using (var myDB = new firstdbEntities())
            {
                var    q      = (from x in myDB.questions where (x.question_id == qId) select x).SingleOrDefault();
                string answer = txtAnswer.Text;

                if (answer == q.answer)
                {
                    lblTrueFalse.Text = "Correct Answer";
                    btnAnswer.Visible = false;
                    txtAnswer.Visible = false;

                    solvedby s          = new solvedby();
                    users    loggeduser = (users)Session["currentuser"];

                    s.question_id = q.question_id;
                    s.user_id     = loggeduser.user_id;

                    myDB.solvedby.Add(s);
                    myDB.SaveChanges();

                    var user = (from u in myDB.users
                                where (loggeduser.user_id == u.user_id)
                                select u).SingleOrDefault();

                    user.point += 1;

                    myDB.SaveChanges();
                }
                else
                {
                    lblTrueFalse.Text = "False Answer";
                }
            }
        }
        protected void ButtonRegister_Click(object sender, EventArgs e)
        {
            using (var myDB = new firstdbEntities())
            {
                var newuser = new users();
                newuser.username      = usernameTxt.Text;
                newuser.email         = emailTxt.Text;
                newuser.password      = passwordTxt.Text;
                newuser.favourite_ide = favideTxt.Text;
                newuser.favourite_pl  = favplTxt.Text;
                newuser.user_type     = "ROLE_USER";
                newuser.is_active     = true;
                newuser.point         = 0;

                myDB.users.Add(newuser);
                myDB.SaveChanges();

                Response.Redirect("Login.aspx");
            }
        }
Beispiel #3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            using (var myDB = new firstdbEntities())
            {
                questions q          = new questions();
                users     loggeduser = (users)Session["currentuser"];

                int id;
                id = myDB.questions.Max(u => u.question_id);

                q.question_id = id + 1;

                q.question_title = TextBoxTitle.Text;
                q.question_text  = TextBoxQuestionText.Text;
                q.answer         = TextBoxQuestionAnswer.Text;
                q.user_id        = loggeduser.user_id;

                myDB.questions.Add(q);
                myDB.SaveChanges();
            }
        }