public async Task <IActionResult> Create([Bind("Id,DataAlteracao,DataCriacao,Nome,Uf,UsuarioAlteracao,UsuarioCriacao")] Municipio municipio) { if (ModelState.IsValid) { _context.Add(municipio); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(municipio)); }
public async Task <IActionResult> Create(CategoriaViewModel model) { if (ModelState.IsValid) { Categoria categoria = new Categoria() { Descricao = model.Descricao, }; db.Add(categoria); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View()); }
public async Task <IActionResult> Create(NoticiaViewModel model) { if (ModelState.IsValid) { Noticia noticia = new Noticia() { Titulo = model.Titulo, Corpo = model.Corpo, DataPublicacao = model.DataPublicacao, Autor = model.Autor, Destaque = model.Destaque, CategoriaId = model.CategoriaId }; db.Add(noticia); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }
public async Task <IActionResult> Create(CategoriaViewModel categoriaViewModel) { try { if (ModelState.IsValid) { var categoria = new Categoria() { Descricao = categoriaViewModel.Descricao }; _dbNoticias.Add(categoria); await _dbNoticias.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(categoriaViewModel)); } catch (Exception ex) { return(RedirectToAction("Index")); } }