public byte[] TraerFoto(int id)
        {
            FOTOS fotos = db.FOTOS.Find(id);

            byte[] cover = fotos.FOTOGRAFIA;
            return(cover);
        }
        public ActionResult EliminarFotoConfirmed(int id)
        {
            FOTOS fOTOS = db.FOTOS.Find(id);

            db.FOTOS.Remove(fOTOS);
            db.SaveChanges();
            return(RedirectToAction("ListaFotos", new { idNoticia = fOTOS.IDNOTICIA }));
        }
        public ActionResult AgregarFoto([Bind(Include = "IDNOTICIA,IDFOTO")] FOTOS fOTOS, HttpPostedFileBase FOTOGRAFIA)
        {
            if (FOTOGRAFIA != null)
            {
                fOTOS.FOTOGRAFIA = new byte[FOTOGRAFIA.ContentLength];
                FOTOGRAFIA.InputStream.Read(fOTOS.FOTOGRAFIA, 0, FOTOGRAFIA.ContentLength);
            }
            if (ModelState.IsValid)
            {
                db.FOTOS.Add(fOTOS);
                db.SaveChanges();
                return(RedirectToAction("ListaFotos", new { idNoticia = fOTOS.IDNOTICIA }));
            }

            ViewBag.IDNOTICIA = new SelectList(db.NOTICIAS, "IDNOTICIA", "TITULO", fOTOS.IDNOTICIA);
            return(View(fOTOS));
        }
 public ActionResult EditarFoto([Bind(Include = "IDNOTICIA,IDFOTO")] FOTOS fOTOS, HttpPostedFileBase FOTOGRAFIA)
 {
     if (FOTOGRAFIA != null && FOTOGRAFIA.ContentLength > 0)
     {
         byte[] imageData = null;
         using (var binaryMunicipio = new BinaryReader(FOTOGRAFIA.InputStream))
         {
             imageData = binaryMunicipio.ReadBytes(FOTOGRAFIA.ContentLength);
         }
         fOTOS.FOTOGRAFIA = imageData;
     }
     if (ModelState.IsValid)
     {
         db.Entry(fOTOS).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("ListaFotos", new { idNoticia = fOTOS.IDNOTICIA }));
     }
     ViewBag.IDNOTICIA = new SelectList(db.NOTICIAS, "IDNOTICIA", "TITULO", fOTOS.IDNOTICIA);
     return(View(fOTOS));
 }
        // GET: FotosTesting/Create
        public ActionResult AgregarFoto(int?idNoticia)
        {
            //Asegurar que a esta vista solo entren aquellos usuarios con rol 1=Capturista
            int  idUsuario = Convert.ToInt32(Session["IDUSUARIO"]);
            byte?rol       = null;

            //linea para validar que no entre a los controladores hasta que detecte una autenticación
            if (idUsuario == 0)
            {
                Response.Redirect("~/Login/Iniciar");
                rol = null;
            }
            //en caso de que si detecte asignar el valor de rol y dar seguridad
            else
            {
                rol = db.USUARIO.Where(s => s.IDUSUARIO == idUsuario).FirstOrDefault().ROL;
                if (rol != 1) // 1 = Capturista
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                }
                else
                {
                    if (idNoticia == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                    }
                    NOTICIAS_SEPLAN Noticias = db.NOTICIAS.Find(idNoticia);
                    if (idNoticia == null)
                    {
                        return(HttpNotFound());
                    }
                    FOTOS fotos = new FOTOS();
                    fotos.IDNOTICIA = idNoticia.Value; // asignar valor de id
                    return(View(fotos));
                }
            }
            return(null);
        }
        // GET: FotosTesting/Edit/5
        public ActionResult EditarFoto(int?id)
        {
            //Asegurar que a esta vista solo entren aquellos usuarios con rol 1=Capturista
            int  idUsuario = Convert.ToInt32(Session["IDUSUARIO"]);
            byte?rol       = null;

            //linea para validar que no entre a los controladores hasta que detecte una autenticación
            if (idUsuario == 0)
            {
                Response.Redirect("~/Login/Iniciar");
                rol = null;
            }
            //en caso de que si detecte asignar el valor de rol y dar seguridad
            else
            {
                rol = db.USUARIO.Where(s => s.IDUSUARIO == idUsuario).FirstOrDefault().ROL;
                if (rol != 1) // 1 = Capturista
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                }
                else
                {
                    if (id == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                    }
                    FOTOS fOTOS = db.FOTOS.Find(id);
                    if (fOTOS == null)
                    {
                        return(HttpNotFound());
                    }
                    ViewBag.IDNOTICIA = new SelectList(db.NOTICIAS, "IDNOTICIA", "TITULO", fOTOS.IDNOTICIA);
                    return(View(fOTOS));
                }
            }
            return(null);
        }
Example #7
0
 public void Incluir(int codcli,string nmarquivo )
 {
     try
     {
         var ft = new FOTOS()
         {
             FOT_CLI_ID = codcli,
             FOT_FOTO = nmarquivo,
             FOT_SELECIONE = 0,
             FOT_DATA = DateTime.Now.ToString("dd/MM/yyyy")
         };
         db.FOTOS.Add(ft);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception("Erro ao tentar incluir uma foto no banco de dados, "+ex.Message);
     }
 }