Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            NE_Carrusel nE_Carrusel = db.NE_Carrusel.Find(id);

            db.NE_Carrusel.Remove(nE_Carrusel);
            System.IO.File.Delete(nE_Carrusel.Ruta);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "CarruselId,Posicion,Texto,Descripcion,Ruta,Extension,NombreArchivo,Activo")] NE_Carrusel nE_Carrusel)
        {
            try
            {
                string             mensaje;
                HttpPostedFileBase postedFile = Request.Files[0];

                if (ModelState.IsValid)
                {
                    if (postedFile != null && postedFile.ContentLength > 0)
                    {
                        IList <string> AllowedFileExtensions = new List <string> {
                            ".jpg", ".gif", ".png"
                        };
                        var ext       = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.'));
                        var extension = ext.ToLower();
                        if (!AllowedFileExtensions.Contains(extension))
                        {
                            mensaje = "Porfavor actualiza la imagen a estension de tipo .jpg,.gif,.png.";
                        }
                        else
                        {
                            var name     = String.Format("banner_{0}", nE_Carrusel.CarruselId);
                            var filePath = Server.MapPath("~/Imagenes/Carrusel/" + name + extension);

                            NE_Carrusel imagen = new NE_Carrusel()
                            {
                                NombreArchivo = name,
                                Extension     = ext,
                                Ruta          = filePath,
                                Posicion      = nE_Carrusel.Posicion,
                                Texto         = nE_Carrusel.Texto,
                                Descripcion   = nE_Carrusel.Descripcion,
                                Activo        = nE_Carrusel.Activo,
                            };
                            db.NE_Carrusel.Add(imagen);
                            db.SaveChanges();

                            NE_Carrusel updateModel = db.NE_Carrusel.Find(imagen.CarruselId);
                            updateModel.NombreArchivo = String.Format("banner_{0}", imagen.CarruselId);
                            db.SaveChanges();
                            filePath = Server.MapPath("~/Imagenes/Carrusel/" + updateModel.NombreArchivo + updateModel.Extension);
                            postedFile.SaveAs(filePath);

                            return(RedirectToAction("Index"));
                        }
                    }
                }
                return(View(nE_Carrusel));
            }
            catch (Exception ex)
            {
                return(View(nE_Carrusel));
            }
        }
Exemplo n.º 3
0
        // GET: Carrusell/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NE_Carrusel nE_Carrusel = db.NE_Carrusel.Find(id);

            if (nE_Carrusel == null)
            {
                return(HttpNotFound());
            }
            return(View(nE_Carrusel));
        }