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()); } }
public static Noticia pesquisar(int id) { using (var ctx = new NoticiaContext()) { return(ctx.Noticia.Find(id)); } }
public static List <Noticia> pesquisar(string Autor) { using (var ctx = new NoticiaContext()) { return(ctx.Noticia.Where(t => t.Autor.Contains(Autor)).ToList()); } }
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" })); }
public IActionResult Index() { NoticiaContext context = HttpContext.RequestServices.GetService(typeof(NoticiaContext)) as NoticiaContext; var noticias = context.getNoticias(); return(View(noticias)); }
public static void deletar(int id) { using (var ctx = new NoticiaContext()) { ctx.Noticia.Remove(ctx.Noticia.Find(id)); ctx.SaveChanges(); } }
public static void cadastrar(Noticia noticia) { using (var ctx = new NoticiaContext()) { ctx.Noticia.Add(noticia); ctx.SaveChanges(); } }
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(); } }
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()); }
public static List <Noticia> listar() { try { using (var ctx = new NoticiaContext()) { return(ctx.Noticia.ToList()); } } catch (Exception) { return(null); }; }