Exemplo n.º 1
0
    protected void ImagenRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "addImageArticulo")
        {
            try
            {
                ImagenProducto data     = new ImagenProducto();
                bool           repetido = false;
                int            imagenId = Convert.ToInt32(e.CommandArgument.ToString());

                data.ImagenId = imagenId;

                data.ProductoId = Convert.ToInt32(ProductoIdHiddenField.Value);
                List <ImagenProducto> listaImgProducto = ImagenProductoBLL.GetImagenProductoById(Convert.ToInt32(ProductoIdHiddenField.Value));
                //List<ImageArticulo> articuloImg = ImageArticuloBLL.GetImagenesArticulo(Convert.ToInt32(CodigoLiteral.Text));
                for (int i = 0; i < listaImgProducto.Count; i++)
                {
                    if (imagenId == listaImgProducto[i].ImagenId)
                    {
                        repetido = true;
                    }
                }
                if (repetido == false)
                {
                    ImagenProductoBLL.InsertImageProducto(data);
                    cargarListaImagenesDelProducto(CodigoLiteral.Text);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorAlert", "alert('La imagen no se puede insertar por que estaria repetida');", true);
                }
            }
            catch (Exception ex)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorAlert", "alert('La imagen no pudo ser insertada al articulo');", true);
                log.Error("La imagen no pudo ser insertada al articulo", ex);
                return;
                //throw ex;
            }
        }
        if (e.CommandName == "removeImage")
        {
            try
            {
                ImagenProducto     data      = new ImagenProducto();
                int                imagenId  = Convert.ToInt32(e.CommandArgument.ToString());
                Imagen             objImagen = ImagenBLL.GetImagenById(imagenId);
                System.IO.FileInfo info      = new System.IO.FileInfo(objImagen.Directorio);
                info.Delete();
                ImagenBLL.DeleteImagen(imagenId);
                cargarImagenesRepeateLista();
            }
            catch (Exception ex)
            {
                log.Error("La imagen no pudo ser insertada al articulo", ex);
                return;
            }
        }
    }
Exemplo n.º 2
0
    protected void SaveImagenButton_Click(object sender, EventArgs e)
    {
        ImagenProducto ObjImagenProducto = new ImagenProducto();

        ObjImagenProducto.ProductoId = Convert.ToInt32(ProductoIdHiddenField.Value);
        ObjImagenProducto.ImagenId   = Convert.ToInt32(ImagenIdHiddenField.Value);
        ImagenProductoBLL.InsertImageProducto(ObjImagenProducto);
        CargarProducto();
        cargarImagenesRepeateLista();
    }
Exemplo n.º 3
0
 protected void ImagenProductoRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     if (e.CommandName == "RemoveImage")
     {
         try
         {
             int ImagenProductoId = Convert.ToInt32(e.CommandArgument.ToString());
             ImagenProductoBLL.DeleteImagenProducto(ImagenProductoId);
             CargarProducto();
         }
         catch (Exception ex)
         {
             log.Error("Error al eliminar la imagen del articulo ", ex);
             return;
         }
     }
 }
Exemplo n.º 4
0
 public void cargarListaImagenesDelProducto(string productoId)
 {
     try
     {
         List <ImagenProducto> listaImgProducto = ImagenProductoBLL.GetImagenProductoById(Convert.ToInt32(productoId));
         if (listaImgProducto.Count == 0)
         {
             errorImagenProductoRepeater.Visible = true;
         }
         else
         {
             errorImagenProductoRepeater.Visible = false;
         }
         ImagenProductoRepeater.DataSource = listaImgProducto;
         ImagenProductoRepeater.DataBind();
     }
     catch (Exception ex)
     {
         log.Error("no se puedo obtener la lista de imagenes del producto con el Id \"" + productoId + "\"");
         throw ex;
     }
 }