protected void btnModificar_Click(object sender, EventArgs e) { try { int id; try { id = Convert.ToInt32(txtId.Text); } catch (Exception ex) { throw new ExcepcionPresentacion("El Id no es un número entero válido."); } Fuente fuente = LogicaFuente.BuscarFuente(Convert.ToInt32(ddlFuente.SelectedValue)); string seccion = txtSeccion.Text; bool imagenIlustrativa = chkImagenIlustrativa.Checked; decimal costo; try { costo = Convert.ToDecimal(txtCosto.Text); } catch (Exception ex) { throw new ExcepcionPresentacion("El Costo no es un número decimal válido."); } string contenido = txtContenido.Text; Articulo articulo = new Articulo(id, seccion, imagenIlustrativa, costo, contenido, fuente); LogicaArticulo.ModificarArticulo(articulo); limpiarFormulario(); lblMensaje.Text = "☺¡Artículo modificado con éxito!"; } catch (ExcepcionSistema ex) { lblMensaje.Text = ex.Message; } catch (Exception ex) { lblMensaje.Text = "¡Error! Ocurrió un error al modificar el artículo."; } }
protected void btnDarAlta_Click(object sender, EventArgs e) { try { Fuente fuente = LogicaFuente.BuscarFuente(Convert.ToInt32(ddlFuente.SelectedValue)); string seccion = txtSeccion.Text; bool imagenIlustrativa = chkImagenIlustrativa.Checked; decimal costo; try { costo = Convert.ToDecimal(txtCosto.Text); } catch (Exception ex) { throw new ExcepcionPresentacion("El Costo no es un número decimal válido."); } string contenido = txtContenido.Text; Articulo articulo = new Articulo(0, seccion, imagenIlustrativa, costo, contenido, fuente); int id; LogicaArticulo.DarAltaArticulo(articulo, out id); limpiarFormulario(); txtId.Text = id.ToString(); lblMensaje.Text = "☺¡Artículo dado de alta con éxito con Id: " + id + "!"; txtId.Focus(); } catch (ExcepcionSistema ex) { lblMensaje.Text = ex.Message; } catch (Exception ex) { lblMensaje.Text = "¡Error! Ocurrió un error al dar de alta el artículo."; } }