示例#1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            SaveImage();

            Producto mProducto = new Producto();

            mProducto.Descripcion  = txtDescripcion.Text;
            mProducto.Nombre       = txtNombre.Text;
            mProducto.Marca        = txtMarca.Text;
            mProducto.Categoria.Id = int.Parse(ddlCategoria.SelectedValue);
            mProducto.Precio       = float.Parse(txtPrecio.Text);
            mProducto.Imagen       = ImagePath;

            if (Request.QueryString["Id"] != null)
            {
                mProducto.Id = int.Parse(Request.QueryString["Id"].ToString());
                ProductoService.UpdateProducto(mProducto);
                Response.Redirect(Request.Url.ToString(), false);
            }
            else
            {
                ProductoService.CreateProduct(mProducto);
                Response.Redirect("ProductForm.aspx?Id=" + mProducto.Id, false);
            }
        }
        catch (Exception ex)
        {
            Response.Redirect("Error.aspx?" + ex.Message);
        }
    }