Beispiel #1
0
        public ActionResult EliminarNoticia(int id)
        {
            noticias noticia = db.noticias.Find(id);
            int      n       = noticia.id_noticia;

            db.noticias.Remove(noticia);
            db.SaveChanges();

            var imagenes = db.imagenes.ToList();

            int idImagen = 0;

            foreach (var i in imagenes)
            {
                if (i.id_noticia == n)
                {
                    idImagen = i.id_imagen;
                }
            }

            imagenes img = db.imagenes.Find(idImagen);

            if (img != null)
            {
                db.imagenes.Remove(img);
                db.SaveChanges();
                String ruta = Path.Combine(Server.MapPath("/Imagenes/"), img.nombre);
                System.IO.File.Delete(ruta);
            }



            return(RedirectToAction("Noticias"));
        }
        public IHttpActionResult registrar([FromBody] Noticia noticia)
        {
            try
            {
                noticias            noticiaDto       = new noticias();
                torneos             torneo           = new torneos();
                categorias_noticias categoriaNoticia = new categorias_noticias();
                clubes club = new clubes();

                noticiaDto.titulo               = noticia.titulo;
                noticiaDto.descripcion          = noticia.descripcion;
                noticiaDto.fecha                = DateTime.Now;
                noticiaDto.id_torneo            = noticia.torneo.id_torneo;
                noticiaDto.id_club              = noticia.club.id_club;
                noticiaDto.id_categoria_noticia = noticia.categoriaNoticia.id_categoria_noticia;
                noticiaDto.tags         = noticia.tags;
                noticiaDto.id_thumbnail = noticia.id_thumbnail;

                db.noticias.Add(noticiaDto);
                db.SaveChanges();
                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.ToString()));
            }
        }
Beispiel #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            noticias noticias = db.noticias.Find(id);

            db.noticias.Remove(noticias);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
 public ActionResult CrearArticulo(noticias noticia)
 {
     if (ModelState.IsValid)
     {
         SQL.Noticias.Add(noticia);
         SQL.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(noticia));
 }
Beispiel #5
0
 public ActionResult Edit([Bind(Include = "codigo,nombre_noticia,descripcion_noticia,foto_noticia")] noticias noticias)
 {
     if (ModelState.IsValid)
     {
         db.Entry(noticias).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(noticias));
 }
Beispiel #6
0
        public ActionResult verArticulo(int id = 0)
        {
            ViewBag.id = id;
            noticias noticias = SQL.Noticias.Find(id);

            if (noticias == null)
            {
                return(HttpNotFound());
            }
            return(View(noticias));
        }
Beispiel #7
0
        public ActionResult Create([Bind(Include = "codigo,nombre_noticia,descripcion_noticia,foto_noticia")] noticias noticias)
        {
            if (ModelState.IsValid)
            {
                db.noticias.Add(noticias);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(noticias));
        }
        public ActionResult Create(noticias noticias)
        {
            if (ModelState.IsValid)
            {
                db.noticias.Add(noticias);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.idUsuario = new SelectList(db.usuarios, "idUsuario", "nomeUsuario", noticias.idUsuario);
            return View(noticias);
        }
Beispiel #9
0
        // GET: noticias/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            noticias noticias = db.noticias.Find(id);

            if (noticias == null)
            {
                return(HttpNotFound());
            }
            return(View(noticias));
        }
Beispiel #10
0
        public ActionResult EditarNoticia(noticias noticia, HttpPostedFileBase imagen)
        {
            db.Entry(noticia).State = EntityState.Modified;
            db.SaveChanges();


            var imagenes = db.imagenes.ToList();

            int id = 0;

            foreach (var i in imagenes)
            {
                if (i.id_noticia == noticia.id_noticia)
                {
                    id = i.id_imagen;
                }
            }

            imagenes img = new imagenes();

            img = db.imagenes.Find(id);
            String ruta = Path.Combine(Server.MapPath("/Imagenes/"), img.nombre);

            System.IO.File.Delete(ruta);


            String Nombre = imagen.FileName;
            String path   = Path.Combine(Server.MapPath("~/Imagenes"), Nombre);

            imagen.SaveAs(path);

            img.id_noticia = noticia.id_noticia;
            img.nombre     = Nombre;
            img.id_imagen  = id;

            db.Entry(img).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Noticias"));
        }
Beispiel #11
0
        public ActionResult NuevaNoticia(noticias noticia, HttpPostedFileBase imagen)
        {
            db.noticias.Add(noticia);
            db.SaveChanges();

            var max = db.noticias.Select(noticias => noticia.id_noticia).Max();

            String Nombre = imagen.FileName;
            String path   = Path.Combine(Server.MapPath("~/Imagenes"), Nombre);

            imagen.SaveAs(path);

            imagenes img = new imagenes();

            img.nombre     = Nombre;
            img.id_noticia = max;

            db.imagenes.Add(img);
            db.SaveChanges();

            return(RedirectToAction("Noticias"));
        }
        public IHttpActionResult update([FromBody] Noticia noticia)
        {
            noticias noticiaDto = new noticias();

            try
            {
                noticiaDto.id_noticia           = noticia.id_noticia.Value;
                noticiaDto.titulo               = noticia.titulo;
                noticiaDto.descripcion          = noticia.descripcion;
                noticiaDto.id_torneo            = noticia.torneo.id_torneo;
                noticiaDto.id_club              = noticia.club.id_club;
                noticiaDto.id_categoria_noticia = noticia.categoriaNoticia.id_categoria_noticia;
                noticiaDto.tags         = noticia.tags;
                noticiaDto.id_thumbnail = noticia.id_thumbnail;


                var result = db.noticias.SingleOrDefault(n => n.id_noticia == noticiaDto.id_noticia);

                if (result != null)
                {
                    result.id_noticia           = noticiaDto.id_noticia;
                    result.titulo               = noticiaDto.titulo;
                    result.descripcion          = noticiaDto.descripcion;
                    result.id_torneo            = noticiaDto.id_torneo;
                    result.id_club              = noticiaDto.id_club;
                    result.id_categoria_noticia = noticiaDto.id_categoria_noticia;
                    result.tags         = noticiaDto.tags;
                    result.id_thumbnail = noticiaDto.id_thumbnail;
                    db.SaveChanges();
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }
 public ActionResult Edit(noticias noticias)
 {
     if (ModelState.IsValid)
     {
         db.Entry(noticias).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.idUsuario = new SelectList(db.usuarios, "idUsuario", "nomeUsuario", noticias.idUsuario);
     return View(noticias);
 }
Beispiel #14
0
        public ActionResult Noticia(int id)
        {
            noticias noticia = db.noticias.Find(id);

            return(View(noticia));
        }