public ActionResult Delete(int id, IFormCollection collection) { try { ItemDeletarViewModel item = new ItemDeletarViewModel(); TryUpdateModelAsync(item); itemDao.Deletar(item); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public void Deletar(ItemDeletarViewModel objeto) { using (var conexao = new SqlConnection(connStr)) { try { conexao.Execute("delete from Item where ID=@id", objeto); conexao.Close(); } catch (Exception e) { throw new Exception("Não foi possível apagar o item!", e); } } }