protected void Page_Load(object sender, EventArgs e) { if (Session["currentuser"] != null) { using (var myDB = new firstdbEntities()) { users loggeduser = (users)Session["currentuser"]; LabelWelcome.Text = loggeduser.username; LabelWelcome.Visible = true; var allusers = (from u in myDB.users select u).ToList(); var count = 0; foreach (var x in allusers) { //TextBoxAllUsers.Text += x.username + " " + x.email + " " + x.password + "\n\n"; count += 1; } Response.Write(count); ListAllUsersGridView.DataSource = allusers; ListAllUsersGridView.DataBind(); } } else { Response.Redirect("Login.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["currentuser"] != null) { using (var myDB = new firstdbEntities()) { /*var allusers = (from u in myDB.leaderboard * orderby u.point descending * select u).ToList();*/ users loggeduser = (users)Session["currentuser"]; LabelWelcome.Text = loggeduser.username; LabelWelcome.Visible = true; var allusers = (from u in myDB.users orderby u.point descending select u).ToList(); LeaderboardGridView.DataSource = allusers; LeaderboardGridView.DataBind(); } } else { Response.Redirect("Login.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["currentuser"] != null) { users loggeduser = (users)Session["currentuser"]; LabelWelcome.Text = loggeduser.username; LabelWelcome.Visible = true; if (Request["id"] != null) { 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(); lblTitle.Text = q.question_title; lblQuestion.Text = q.question_text; } } } else { Response.Redirect("Login.aspx"); } } }
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"); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["currentuser"] != null) { users loggeduser = (users)Session["currentuser"]; LabelWelcome.Text = loggeduser.username; LabelWelcome.Visible = true; using (var myDB = new firstdbEntities()) { var q = (from x in myDB.questions select x).ToList(); DataList1.DataSource = q; DataList1.DataBind(); } } else { Response.Redirect("Login.aspx"); } }
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(); } }
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 ButtonLogin_Click(object sender, EventArgs e) { using (var myDB = new firstdbEntities()) { users loggeduser = (from u in myDB.users where u.email == TextBoxEmail.Text && u.password == TextBoxPass.Text select u).SingleOrDefault(); if (loggeduser != null) { Session["currentuser"] = loggeduser; if (loggeduser.user_type == "ROLE_ADMIN") { Response.Redirect("Admin.aspx"); } else { Response.Redirect("Home.aspx"); } } } }