public async Task <IActionResult> Edit(int id, [Bind("Id,Nome")] Departamento departamento) { if (id != departamento.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(departamento); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartamentoExists(departamento.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(departamento)); }
public async Task UpdateAsync(Produto obj) { bool hasAny = await _context.Produto.AnyAsync(x => x.Id == obj.Id); if (!hasAny) //Tem algum registro { throw new NotFoundException("Id not found"); } try { _context.Update(obj); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException e) { throw new DbConcurrencyException(e.Message); } }