public async Task <IActionResult> Edit(int id, [Bind("Id,RazaoSocial,CNPJ,UF")] Empresa empresa) { if (id != empresa.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(empresa); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmpresaExists(empresa.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(empresa)); }
public async Task UpdateAsync(Fornecedor obj) { bool hasAny = await _context.Fornecedor.AnyAsync(x => x.Id == obj.Id); if (!hasAny) { throw new NotFoundException("Id não encontrado"); } try { _context.Update(obj); await _context.SaveChangesAsync(); } catch (DbConcurrencyException e) { throw new DbConcurrencyException(e.Message); } }