public async Task <IActionResult> Edit(int id, [Bind("Id,NomeDoCurso")] Curso curso) { if (id != curso.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(curso); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CursoExists(curso.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(curso)); }
public async Task UpdateAsync(Professor obj) { bool hasAny = await _context.Professor.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); } }