Пример #1
0
        protected void editProfileController(object sender, EventArgs e)
        {
            registrationErrorHandler editHandler = new registrationErrorHandler();

            if (newPhoneNumber.Text == "")
            {
                editHandler.emptyPhoneNumber();
            }
            if (!newPhoneNumber.Text.All(char.IsDigit))
            {
                editHandler.invalidPhoneNumber();
            }
            if (newDescription.Text == "")
            {
                editHandler.emptyDescription();
            }

            if (editHandler.error == "")
            {
                int    phone       = int.Parse(newPhoneNumber.Text);
                string description = newDescription.Text;
                currUser.modifyAccount(phone, description);
                general_dialog.Visible = false;
                Session["success"]     = "editProfile";
                Response.Redirect("main.aspx");
            }

            else
            {
                general_dialog.InnerHtml = editHandler.error;
                general_dialog.Visible   = true;
            }
        }
Пример #2
0
        protected void adminSuspendUserController(object sender, EventArgs e)
        {
            registrationErrorHandler suspendHandler = new registrationErrorHandler();

            if (suspendUserField.Text == "")
            {
                suspendHandler.emptyUserName();
            }

            // Fetch the user object that needs to be suspended
            user suspendedUser = fetchUserObject(suspendUserField.Text);

            if (suspendUserField.Text != "")
            {
                if (suspendedUser == null)
                {
                    suspendHandler.userNameNotExists();
                }
            }


            if (suspendHandler.error == "")
            {
                // Change user to suspended status
                suspendedUser.setStatus(1);

                // Write back the user object to database
                currAdmin.suspendUser(suspendedUser);
                adminDialog.Visible = false;
                Session["success"]  = "adminSuspendUser";
                Response.Redirect("main.aspx");
            }

            else
            {
                adminDialog.InnerHtml = suspendHandler.error;
                adminDialog.Visible   = true;
            }
        }
Пример #3
0
        protected void adminCreaterUserController(object sender, EventArgs e)
        {
            registrationErrorHandler regHandler = new registrationErrorHandler();

            if (regUserName.Text == "")
            {
                regHandler.emptyUserName();
            }
            if (regPassword.Text == "")
            {
                regHandler.emptyPassword();
            }
            if (regRealName.Text == "")
            {
                regHandler.emptyRealName();
            }
            if (regEmail.Text == "")
            {
                regHandler.emptyEmail();
            }
            if (!regEmail.Text.Contains("@"))
            {
                regHandler.invalidEmail();
            }
            if (regPhone.Text == "")
            {
                regHandler.emptyPhoneNumber();
            }
            if (!regPhone.Text.All(char.IsDigit))
            {
                regHandler.invalidPhoneNumber();
            }
            if (regDescription.Text == "")
            {
                regHandler.emptyDescription();
            }


            // Check username exists
            SqlConnection con    = new SqlConnection(ConfigurationManager.ConnectionStrings["vetoTours"].ToString());
            SqlCommand    cmd    = null;
            SqlDataReader reader = null;

            con.Open();
            string query = "SELECT * FROM users WHERE userID='" + regUserName.Text + "';";

            cmd    = new SqlCommand(query, con);
            reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                if (reader.GetString(0) == regUserName.Text)
                {
                    regHandler.userNameExists();
                }
            }
            con.Close();

            if (regHandler.error == "")
            {
                user newUser = new user(regUserName.Text, regPassword.Text, regRealName.Text, regEmail.Text, int.Parse(regPhone.Text), regDescription.Text, int.Parse(ddRegStat.SelectedValue));
                currAdmin.createUser(newUser);
                adminDialog.Visible = false;
                Session["success"]  = "adminCreateUser";
                Response.Redirect("main.aspx");
            }

            else
            {
                adminDialog.InnerHtml = regHandler.error;
                adminDialog.Visible   = true;
            }
        }
Пример #4
0
        protected void adminEditUserController(object sender, EventArgs e)
        {
            registrationErrorHandler editHandler = new registrationErrorHandler();

            if (editUserID.Text == "")
            {
                editHandler.emptyUserName();
            }
            if (editPassword.Text == "")
            {
                editHandler.emptyPassword();
            }
            if (editRealName.Text == "")
            {
                editHandler.emptyRealName();
            }

            if (editEmail.Text == "")
            {
                editHandler.emptyEmail();
            }
            else if (!editEmail.Text.Contains("@"))
            {
                editHandler.invalidEmail();
            }

            if (editPhone.Text == "")
            {
                editHandler.emptyPhoneNumber();
            }
            if (!editPhone.Text.All(char.IsDigit))
            {
                editHandler.invalidPhoneNumber();
            }
            if (editDesc.Text == "")
            {
                editHandler.emptyDescription();
            }

            // Fetch the user object from database
            user targetUser = fetchUserObject(editUserID.Text);

            if (targetUser == null)
            {
                editHandler.userNameNotExists();
            }


            if (editHandler.error == "")
            {
                // Edit the user object based on the provided fields
                targetUser.setPassword(editPassword.Text);
                targetUser.setName(editRealName.Text);
                targetUser.setEmail(editEmail.Text);
                targetUser.setPhoneNumber(int.Parse(editPhone.Text));
                targetUser.setPersonalDescription(editDesc.Text);
                targetUser.setStatus(int.Parse(ddEditStat.SelectedValue));

                currAdmin.editUser(targetUser);
                adminDialog.Visible = false;
                Session["success"]  = "adminEditUser";
                Response.Redirect("main.aspx");
            }

            else
            {
                adminDialog.InnerHtml = editHandler.error;
                adminDialog.Visible   = true;
            }
        }