public async Task <IActionResult> Edit(int id, [Bind("Id,Uf,TradingName,Cnpj")] Company company) { if (!ModelState.IsValid) { return(View(company)); } if (id != company.Id) { return(RedirectToAction(nameof(Error), new { message = "Id mismatch" })); } if (ModelState.IsValid) { try { _context.Update(company); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompanyExists(company.Id)) { return(RedirectToAction(nameof(Error), new { message = "Company not found" })); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(company)); }
public async Task UpdateAsync(Purveyor obj) { bool hasAny = await _context.Purveyor.AnyAsync(x => x.Id == obj.Id); if (!hasAny) { throw new NotFoundException("Id not found"); } try { _context.Update(obj); await _context.SaveChangesAsync(); } catch (DbConcurrencyException e) { throw new DbConcurrencyException(e.Message); } }