Exemple #1
0
        protected void crearUsuario(object sender, EventArgs e)
        {
            try
            {
                List <Usuario> existen = iUs.getByCriterio <Usuario>("", "", txt_username.Text);
                if (existen.Count == 0)
                {
                    if (ddl_perfil.SelectedValue == "0")
                    {
                        String msj = "Seleccione un perfil.";
                        this.Page.Response.Write("<script language='JavaScript'>window.alert('" + msj + "');</script>");
                    }
                    else
                    {
                        usuario       = new Usuario();
                        usuario.login = txt_username.Text.Trim();
                        password      = txt_password.Text.Trim();
                        String hash = Encripta.EncodePassword(string.Concat(usuario.login, password));
                        usuario.contraseña    = hash;
                        usuario.fechaVigencia = DateTime.Now.Date;
                        //verificar el tipo del estado
                        usuario.estado = true;
                        Persona p = iPers.getByCriterio <Persona>("", "", txt_persona.Text).First <Persona>();
                        usuario.codigoPersona = p.codigoPersona;
                        usuario.codigoUsuario = generarCodigoUsuario();
                        usuario.mail          = txt_correo.Text;
                        usuario.recibeAlertas = cheq_alerta.Checked;

                        perf           = iPerf.getPorCriterio <Perfil>(ddl_perfil.SelectedValue.ToString()).First <Perfil>();
                        usuario.perfil = perf.codigoPerfil;

                        iUs.save <Usuario>(usuario);
                        String msj = "El usuario ha sido creado correctamente.";
                        Intermediario.confirmarCambios();
                        this.Page.Response.Write("<script language='JavaScript'>window.alert('" + msj + "');</script>");

                        txt_apellido.Text   = "";
                        txt_codigo.Text     = "";
                        txt_nombre.Text     = "";
                        txt_password.Text   = "";
                        txt_persona.Text    = "";
                        txt_username.Text   = "";
                        txt_correo.Text     = "";
                        cheq_alerta.Checked = false;
                    }
                }
                else
                {
                    String msj = "El nombre de usuario ingresado ya existe. Por favor ingrese otro usuario.";
                    this.Page.Response.Write("<script language='JavaScript'>window.alert('" + msj + "');</script>");
                    txt_username.Text = "";
                    txt_password.Text = "";
                }
            }
            catch (Exception) {
            }
        }