예제 #1
0
        public ActionResult Create([Bind(Include = "ID,DIRECCION,TITULO,ID_SITIO")] FOTO_SITIO fOTO_SITIO)
        {
            HttpPostedFileBase FileBase = Request.Files[0];

            try
            {
                WebImage image = new WebImage(FileBase.InputStream);
                fOTO_SITIO.DIRECCION = image.GetBytes();
            }
            catch
            {
                ModelState.AddModelError("", "Es Obligatorio llenar el campo foto");
            }

            if (ModelState.IsValid)
            {
                db.FOTO_SITIO.Add(fOTO_SITIO);
                db.SaveChanges();
                ModelState.AddModelError("", "Se agrego la foto, puede subir mas si lo desea");
                return(RedirectToAction("Create/" + fOTO_SITIO.ID_SITIO.ToString()));
            }

            ViewBag.ID_SITIO = new SelectList(db.SITIO_TURISTICO, "ID", "NOMBRE", fOTO_SITIO.ID_SITIO);
            return(View(fOTO_SITIO));
        }
예제 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            FOTO_SITIO fOTO_SITIO = db.FOTO_SITIO.Find(id);

            db.FOTO_SITIO.Remove(fOTO_SITIO);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #3
0
        // GET: FOTO_SITIO/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FOTO_SITIO fOTO_SITIO = db.FOTO_SITIO.Find(id);

            if (fOTO_SITIO == null)
            {
                return(HttpNotFound());
            }
            return(View(fOTO_SITIO));
        }
예제 #4
0
        public ActionResult GetImage(int id)
        {
            FOTO_SITIO fotoSitio = db.FOTO_SITIO.Find(id);

            byte[] byteImage = fotoSitio.DIRECCION;

            MemoryStream memoryStream = new MemoryStream(byteImage);
            Image        image        = Image.FromStream(memoryStream);

            memoryStream = new MemoryStream();
            image.Save(memoryStream, ImageFormat.Jpeg);
            memoryStream.Position = 0;

            return(File(memoryStream, "image/jpg"));
        }
예제 #5
0
        // GET: FOTO_SITIO/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FOTO_SITIO fOTO_SITIO = db.FOTO_SITIO.Find(id);

            if (fOTO_SITIO == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ID_SITIO = new SelectList(db.SITIO_TURISTICO, "ID", "NOMBRE", fOTO_SITIO.ID_SITIO);
            return(View(fOTO_SITIO));
        }
예제 #6
0
        public ActionResult Edit([Bind(Include = "ID,DIRECCION,TITULO,ID_SITIO")] FOTO_SITIO fOTO_SITIO)
        {
            byte[]             imagenActual = null;
            HttpPostedFileBase FileBase     = Request.Files[0];

            if (FileBase == null)
            {
                imagenActual = db.FOTO_SITIO.SingleOrDefault(t => t.ID == fOTO_SITIO.ID).DIRECCION;
            }
            else
            {
                WebImage image = new WebImage(FileBase.InputStream);
                fOTO_SITIO.DIRECCION = image.GetBytes();
            }

            if (ModelState.IsValid)
            {
                db.Entry(fOTO_SITIO).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.ID_SITIO = new SelectList(db.SITIO_TURISTICO, "ID", "NOMBRE", fOTO_SITIO.ID_SITIO);
            return(View(fOTO_SITIO));
        }