public IHttpActionResult Delete(string name)
 {
     try
     {
         ArchivoBLL archivoBLL = new ArchivoBLL();
         archivoBLL.EliminarImagen(name);
         return(Content(HttpStatusCode.OK, "La imagen se eliminó correctamente " + name));
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// ////////////////////////////////////////////
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private string SubirImagen(HttpPostedFileBase file)
        {
            string nombre = "";

            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    ArchivoBLL modelo = new ArchivoBLL();
                    nombre = DateTime.Now.ToString("yyyyMMddHHmmss") + file.FileName;
                    string path = Server.MapPath("~/Content/Imagenes/") + nombre;
                    modelo.SubirArchivo(path, file);
                    ViewBag.Message = modelo.confirmacion;
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            }
            return(nombre);
        }
        private string SubirImagen(HttpPostedFile file)
        {
            string nombre = "";

            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    ArchivoBLL modelo = new ArchivoBLL();
                    nombre = DateTime.Now.ToString("yyyyMMddHHmmss") + file.FileName;
                    string path = HttpContext.Current.Server.MapPath("~/Content/Imagenes/") + nombre;
                    modelo.SubirArchivo(path, file);
                    return(path);
                }
                catch (UnsupportedMediaTypeException)
                {
                    return("");
                }
            }
            return(nombre);
        }
Esempio n. 4
0
        private void EliminarArchivo(string prd_img)
        {
            string path = Server.MapPath("~/Content/Imagenes/") + prd_img;

            try
            {
                ArchivoBLL modelo = new ArchivoBLL();
                modelo.EliminarArchivo(path);
                if (modelo.ComprobarRuta(path))
                {
                    ViewBag.Message = modelo.error;
                }
                else
                {
                    ViewBag.Message = modelo.confirmacion;
                }
            }
            catch (Exception ex)
            {
                ViewBag.Message = "ERROR:" + ex.Message.ToString();
            }
        }
 public IHttpActionResult Post()
 {
     try
     {
         string imageName   = null;
         var    httpRequest = System.Web.HttpContext.Current.Request;
         //Upload Image
         HttpPostedFile postedFile = httpRequest.Files["image"];
         ArchivoBLL     archivoBLL = new ArchivoBLL();
         imageName = archivoBLL.SubirImagen(postedFile);
         if (imageName != "")
         {
             return(Content(HttpStatusCode.OK, imageName));
         }
         else
         {
             return(Content(HttpStatusCode.Conflict, "Error la imagen entro en conflicto Crear"));
         }
     }
     catch (Exception)
     {
         return(Content(HttpStatusCode.UnsupportedMediaType, "Error Imagen no soportada"));
     }
 }