Esempio n. 1
0
        protected void Register_Click(object sender, EventArgs e)
        {
            if (!isValidEmail(inputEmail.Text))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Invalid Email Address!')", true);
            }

            // invalid email

            else
            {
                String t;
                if (radio_student.Checked)
                {
                    t = "student";
                }
                else
                {
                    t = "teacher";
                }


                using (var db = new webProjectEntities())
                {
                    var newUser = new tableUsers()
                    {
                        ID               = inputid.Text,
                        Email            = inputEmail.Text,
                        Password         = inputPassword.Text,
                        Fullname         = inputFullname.Text,
                        Algebra          = "",
                        Algorithms       = "",
                        Datamining       = "",
                        WebDev           = "",
                        Calculus         = "",
                        OperatinsSystems = "",
                        type             = t
                    };

                    try
                    {
                        db.tableUsers.Add(newUser);
                        db.SaveChanges();
                        RegisteredSuccess.Visible       = true;
                        RequiredFieldValidator.Visible  = false;
                        RequiredFieldValidator1.Visible = false;
                        RequiredFieldValidator2.Visible = false;
                        gotoLogin.Visible   = true;
                        backToLogin.Visible = false;
                    }
                    catch (Exception ex)
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ID already exists')", true);
                    }
                }
            }
        }
Esempio n. 2
0
 protected void Login_Click(object sender, EventArgs e)
 {
     using (var db = new webProjectEntities())
     {
         var user = db.tableUsers.Where(i => i.ID == inputID.Text &&
                                        i.Password == inputPassword.Text).FirstOrDefault();
         if (user == null)
         {
             pnlMessage.Visible = true;
             loginBtn.Visible   = true;
         }
         else
         {
             Session["Email"]    = user.Email;
             Session["type"]     = user.type;
             Session["ID"]       = user.ID;
             Session["Fullname"] = user.Fullname;
             Response.Redirect("Homepage.aspx");
         }
     }
 }
Esempio n. 3
0
        protected void addNewStudent(object sender, EventArgs e)
        {
            Session["returnToPage"] = "6";
            toStudentTbl.Visible    = false;
            if (newStudentEmail.Text.Length == 0 || newStudentID.Text.Length == 0 || newStudentPassword.Text.Length == 0) // mandatory fields are empty
            {
                addStudent_lbl.Visible = true;
            }

            else // form is filled OK
            {
                if (!isValidEmail(newStudentEmail.Text))
                {
                    addStudent_lbl.Visible = false;
                    toStudentTbl.Visible   = false;
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Invalid Email Address!')", true);
                }
                else
                {
                    using (var db = new webProjectEntities())
                    {
                        var newUser = new tableUsers()
                        {
                            ID               = newStudentID.Text,
                            Email            = newStudentEmail.Text,
                            Password         = newStudentPassword.Text,
                            Fullname         = newStudentFullname.Text.Length == 0 ? "" : newStudentFullname.Text,
                            Algebra          = "",
                            Algorithms       = "",
                            Datamining       = "",
                            WebDev           = "",
                            Calculus         = "",
                            OperatinsSystems = "",
                            type             = "student"
                        };

                        newStudentEmail.Text    = "";
                        newStudentID.Text       = "";
                        newStudentPassword.Text = "";
                        newStudentFullname.Text = "";

                        try
                        {
                            db.tableUsers.Add(newUser);
                            db.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ID already exists')", true);
                            addStudent_lbl.Visible = false;
                            toStudentTbl.Visible   = false;
                            return;
                        }
                    }
                    addStudent_lbl.ForeColor = System.Drawing.Color.Green;
                    addStudent_lbl.Text      = "New Student Added Successfully";
                    addStudent_lbl.Visible   = true;
                    toStudentTbl.Attributes.Add("style", "margin-left: 25px;");
                    toStudentTbl.Visible = true;
                }
            }
        }