//Volvemos private void btnVolver_Click(object sender, RoutedEventArgs e) { Button btnClicado = (Button)sender; switch (btnClicado.Content) { case "Modificar": { if (Utils.Utils.VerificarCampos(new List <string>() { tbContra.Text, tbUsuario.Text }) == true) { try { using (var context = new DAOUsuarios()) { //Comprobamos que el nuevo nombre esté disponible if (context.ComprobarExistencia(tbUsuario.Text.Trim(), this.Usuario.Username) == false) { Usuario nuevo = new Usuario() { ID = this.Usuario.ID, Username = tbUsuario.Text.Trim(), Password = tbContra.Text.Trim(), Genero = (cbGenero.SelectedIndex == 0) ? true : false, }; //Modificamos if (context.ModificarPerfil(nuevo) == false) { throw new Exception("Ha ocurrido un error al modificar el perfil"); } else { this.ResultadoPerfil = ResultadoPerfil.Modificar; //Hemos modificado Utils.Utils.CentralizarMensajes("Los nuevos datos han sido guardados"); this.Close(); } } else { throw new Exception("Ya existe dicho nombre de usuario"); } } } catch (Exception err) { MessageBox.Show(err.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { Utils.Utils.CentralizarMensajes("Para modificar el perfil se deben de introducir todos los datos"); } } break; case "Volver": { this.ResultadoPerfil = ResultadoPerfil.Volver; this.Close(); } break; } }