Пример #1
0
 public static List <Noticia> pesquisarTudo(string pesquisa)
 {
     using (var ctx = new NoticiaContext())
     {
         return(ctx.Noticia.Where(t => t.Autor.Contains(pesquisa) || t.Titulo.Contains(pesquisa) || t.Mensagem.Contains(pesquisa)).ToList());
     }
 }
Пример #2
0
 public static Noticia pesquisar(int id)
 {
     using (var ctx = new NoticiaContext())
     {
         return(ctx.Noticia.Find(id));
     }
 }
Пример #3
0
 public static List <Noticia> pesquisar(string Autor)
 {
     using (var ctx = new NoticiaContext())
     {
         return(ctx.Noticia.Where(t => t.Autor.Contains(Autor)).ToList());
     }
 }
Пример #4
0
        public async Task <IActionResult> NuevoAsync(string inputNombre, string inputFecha, int selectEvento, string inputNoticia, IFormFile inputImagen)
        {
            if (inputImagen == null || inputImagen.Length == 0)
            {
                return(Content("file not selected"));
            }
            var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\", inputImagen.FileName);

            if (inputNoticia == null)
            {
                return(Content("file not selected"));
            }
            using (var stream = new FileStream(path, FileMode.Create))
            {
                await inputImagen.CopyToAsync(stream);
            }
            string         filePath = inputImagen.FileName;
            NoticiaContext context  = HttpContext.RequestServices.GetService(typeof(NoticiaContext)) as NoticiaContext;
            bool           result   = context.nuevaNoticia(inputNombre, inputFecha, inputNoticia, selectEvento, filePath);

            if (result)
            {
                return(RedirectToAction("Nuevo", "Noticia", new { result = "Success" }));
            }
            return(RedirectToAction("Nuevo", "Noticia", new { result = "Failure" }));
        }
Пример #5
0
        public IActionResult Index()
        {
            NoticiaContext context  = HttpContext.RequestServices.GetService(typeof(NoticiaContext)) as NoticiaContext;
            var            noticias = context.getNoticias();

            return(View(noticias));
        }
Пример #6
0
 public static void deletar(int id)
 {
     using (var ctx = new NoticiaContext())
     {
         ctx.Noticia.Remove(ctx.Noticia.Find(id));
         ctx.SaveChanges();
     }
 }
Пример #7
0
 public static void cadastrar(Noticia noticia)
 {
     using (var ctx = new NoticiaContext())
     {
         ctx.Noticia.Add(noticia);
         ctx.SaveChanges();
     }
 }
Пример #8
0
 public static void editar(int id, Noticia noticia)
 {
     using (var ctx = new NoticiaContext())
     {
         ctx.Noticia.Find(id).Autor    = noticia.Autor;
         ctx.Noticia.Find(id).Mensagem = noticia.Mensagem;
         ctx.Noticia.Find(id).Titulo   = noticia.Titulo;
         ctx.Noticia.Find(id).Data     = DateTime.Now;
         ctx.SaveChanges();
     }
 }
Пример #9
0
        public IActionResult Edit(int id, string result)
        {
            if (result != null)
            {
                ViewBag.result = result;
            }
            EventoContext  eventos = HttpContext.RequestServices.GetService(typeof(EventoContext)) as EventoContext;
            NoticiaContext noticia = HttpContext.RequestServices.GetService(typeof(NoticiaContext)) as NoticiaContext;

            ViewBag.noticia = noticia.getNoticia(id);
            ViewBag.eventos = eventos.getEventos();
            return(View());
        }
Пример #10
0
 public static List <Noticia> listar()
 {
     try
     {
         using (var ctx = new NoticiaContext())
         {
             return(ctx.Noticia.ToList());
         }
     }
     catch (Exception)
     {
         return(null);
     };
 }