public async Task <IActionResult> Edit(int id, Noticia noticia) { if (!ModelState.IsValid) { var autors = await _autorService.FindAllAsync(); var viewModel = new NoticiaFormViewModel { Noticia = noticia, Autors = autors }; return(View(viewModel)); } if (id != noticia.Id) { return(RedirectToAction(nameof(Error), new { message = "Id não correspondem" })); } try { await _noticiaService.UpdateAsync(noticia); return(RedirectToAction(nameof(Index))); } catch (NotFoundException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } catch (DbConcurrencyException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } }
public async Task <IActionResult> Create() { var autors = await _autorService.FindAllAsync(); var viewModel = new NoticiaFormViewModel { Autors = autors }; return(View(viewModel)); }
public async Task <IActionResult> Create(Noticia noticia) { if (!ModelState.IsValid) { var autors = await _autorService.FindAllAsync(); var viewModel = new NoticiaFormViewModel { Noticia = noticia, Autors = autors }; return(View(viewModel)); } await _noticiaService.InsertAsync(noticia); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(RedirectToAction(nameof(Error), new { message = "Id não fornecido" })); } var obj = await _noticiaService.FindByIdAsync(id.Value); if (obj == null) { return(RedirectToAction(nameof(Error), new { message = "Notícia não encontrada" })); } List <Autor> autors = await _autorService.FindAllAsync(); NoticiaFormViewModel viewModel = new NoticiaFormViewModel { Noticia = obj, Autors = autors }; return(View(viewModel)); }