public ActionResult Edit(EditorAutorViewModel model) { if (!ModelState.IsValid) { return(View(model)); } Autor autor = _repositorio.ObterPorId(model.Id); autor.Nome = model.Nome; try { if (_repositorio.Atualizar(autor)) { return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError("Mensagem", ex.Message); return(View(model)); } return(View(autor)); }
public ActionResult Create(EditorAutorViewModel model) { if (!ModelState.IsValid) { return(View(model)); } Autor autor = new Autor { Nome = model.Nome }; try { if (_repositorio.Inserir(autor)) { return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError("Mensagem", ex.Message); return(View(model)); } return(View(autor)); }
public ActionResult Edit(int id) { EditorAutorViewModel model = PreencherAutorModel(id); ViewData.Add(nameof(eStatusForm), (int)eStatusForm.Alterar); return(View(model)); }
public ActionResult View(int id) { ViewData.Add(nameof(eStatusForm), (int)eStatusForm.Visualizar); EditorAutorViewModel model = PreencherAutorModel(id); return(View(model)); }
public ActionResult Delete(int id) { ViewData.Add(nameof(eStatusForm), (int)eStatusForm.Excluir); EditorAutorViewModel model = PreencherAutorModel(id); return(View(model)); }
public ActionResult Create() { var model = new EditorAutorViewModel { Nome = "" }; ViewData.Add(nameof(eStatusForm), (int)eStatusForm.Novo); return(View(model)); }
private EditorAutorViewModel PreencherAutorModel(int id) { var autor = _repositorio.ObterPorId(id); var model = new EditorAutorViewModel { Id = autor.Id, Nome = autor.Nome }; return(model); }
public ActionResult DeleteConfirm(EditorAutorViewModel model) { Autor autor = _repositorio.ObterPorId(model.Id); if (_repositorio.Excluir(autor.Id)) { return(RedirectToAction("Index")); } return(View(model)); }