Ejemplo n.º 1
0
        private void buttonGuardar_Click(object sender, EventArgs e)
        {
            String  nombreRol = textBoxNombreRol.Text.Trim();
            Boolean activo    = checkBoxActivo.Checked;
            List <Funcionalidad> funcionalidades = new List <Funcionalidad>();
            RepositorioRol       repositorioRol  = new RepositorioRol();

            foreach (DataGridViewRow row in dataGridFuncionalidades.SelectedRows)
            {
                funcionalidades.Add((Funcionalidad)row.DataBoundItem);
            }

            //CAMBIO LOS ATRIBUTOS DEL ROL
            rol.setNombre(nombreRol);
            rol.setActivo(activo);
            rol.setFuncionalidades(funcionalidades);

            //LA RESPONSABILIDAD DE VALIDAR EL INPUT LA DEJO EN LA INTERFAZ???
            //O MEJOR EN EL REPOSITORIO Y LAS MANEJO CON EXCEPCIONES???
            if (this.validoInput(this))
            {
                try
                {
                    repositorioRol.update(rol);
                    MessageBox.Show("Rol actualizado con éxito.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    //ME TRAIGO EL ROL ACTUALIZADO
                    this.rol = repositorioRol.getById(rol.getIdRol());
                    this.inicializarResetear();
                }
                //catch (NoExisteIDException exc)
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Ingrese nombre del Rol y seleccione sus Funcionalidades", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }