Ejemplo n.º 1
0
        private void RemoveUser_Load(object sender, EventArgs e)
        {
            Users userDataAccessClass = new Users();
            List<User> allUsers = userDataAccessClass.List();

            cboUsername.Items.AddRange(allUsers.ToArray());
        }
Ejemplo n.º 2
0
        protected void btnAddUser_Click(object sender, EventArgs e)
        {
            try
            {
                Users oUser = oUser = new Users().Get(int.Parse(Request.QueryString["PersonaId"]));

                if (oUser != null)
                {
                    oUser.Activo = this.ddlActivo.SelectedValue == "1" ? true : false;
                    oUser.RolId = Convert.ToInt32(ddlRol.SelectedValue);
                    oUser.Salt = Security.GenerateSalt().ToString();
                    oUser.Password = Security.GetSHA512WithSalt(txtPirulo.Text.Trim(), oUser.Salt);

                    new Users().Update(oUser);
                }
                else
                {
                    oUser = new Users();

                    oUser.Activo = this.ddlActivo.SelectedValue == "1" ? true : false;
                    oUser.RolId = Convert.ToInt32(ddlRol.SelectedValue);
                    oUser.PersonaId = int.Parse(Request.QueryString["PersonaId"]);
                    oUser.Salt = Security.GenerateSalt().ToString();
                    oUser.Password = Security.GetSHA512WithSalt(txtPirulo.Text.Trim(), oUser.Salt);

                    new Users().Insert(oUser);
                }

                this.ClientScript.RegisterStartupScript(this.GetType(), "User", "alert('El usuario fue creado/modificado con exito.');", true);
            }
            catch (Exception ex)
            {
                this.lblErrorUsuario.Text = ex.Message;
            }
        }
Ejemplo n.º 3
0
        public void Insert(Users user)
        {
            try
            {
                using (var context = new QuirofanoEntities())
                {
                    context.Users.AddObject(user);

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Message.Contains("23505"))
                    throw new Exception("Error: no puede asignar dos formas de pago con la misma descripción.");
            }
        }
Ejemplo n.º 4
0
        public void Update(Users user)
        {
            using (var context = new QuirofanoEntities())
            {
                //Users user2 = context.Users.First(i => i.PersonaId == user.PersonaId);

                //user2.Password = user.Password;
                //user2.Activo = user.Activo;
                //user2.RolId = user.RolId;

                //context.SaveChanges();

                context.Users.Attach(context.Users.Single(i => i.UserId == user.UserId));

                context.Users.ApplyCurrentValues(user);

                int inte = context.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave);
            }
        }
Ejemplo n.º 5
0
        protected void FillDataUser()
        {
            Users oUser = new Users().Get(Convert.ToInt32(Request.QueryString["PersonaId"]));
            if (oUser != null)
            {
                this.ddlRol.SelectedValue = oUser.RolId.ToString();
                if (oUser.Activo == true)
                    this.ddlActivo.SelectedValue = "1";
                else
                    this.ddlActivo.SelectedValue = "0";

                this.btnAddUser.Text = "Actualizar";
            }
            else
            {
                this.lblEstadoUsuario.Text = "USUARIO NO GENERADO";
            }
            this.txtPirulo.Text = "";
        }
Ejemplo n.º 6
0
        private void btnNewUserSave_Click(object sender, EventArgs e)
        {
            // validate username
            if (string.IsNullOrEmpty(txtUsername.Text))
            {
                MessageBox.Show(
                    "Please enter a valid Username.",
                    "Input Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                txtUsername.Focus();
            }
            else if (txtUsername.TextLength < 4)
            {
                MessageBox.Show(
                    "Username must have a minimum of 4 characters.",
                    "Input Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                txtUsername.Focus();
                txtUsername.SelectionStart = 0;
                txtUsername.SelectionLength = txtUsername.Text.Length;
            }

            // validate password
            else if (string.IsNullOrEmpty(txtPassword.Text))
            {
                MessageBox.Show(
                    "Password cannot be blank.",
                    "Input Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                txtPassword.Focus();
            }
            else if (txtPassword.TextLength < 6 | txtPassword.TextLength > 10)
            {
                MessageBox.Show(
                    "Password must be between 6 and 10 characters.",
                    "Input Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                txtPassword.Focus();
                txtPassword.SelectionStart = 0;
                txtPassword.SelectionLength = txtPassword.Text.Length;
            }
            else
            {
                try
                {
                    // check if username exists
                    Users userCheck = new Users();

                    if (userCheck.UsernameCheck(txtUsername.Text))
                    {
                        MessageBox.Show(
                            "This Username already exists.\n\nPlease enter another Username.",
                            "Username in use",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);

                        txtUsername.Text = "";
                        txtPassword.Text = "";
                        txtUsername.Focus();
                    }
                    else
                    {
                        Users newUser = new Users();
                        newUser.Insert(
                            txtUsername.Text,
                            txtPassword.Text);

                        MessageBox.Show(string.Format(
                            "Username \"{0}\" created successfully.",
                            txtUsername.Text),
                            "Confirmation",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

                        this.Close();

                    }
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(
                        string.Format(
                        "Database error:\n\n{0}. \n\nPlease contact [email protected]", ex.Message),
                        "Connection Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        string.Format(
                        "The following error has occoured:\n\n{0}. \n\nPlease contact [email protected]", ex.Message),
                        "Connection Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
            }
        }