コード例 #1
0
 //Metodo Update
 public async Task UpdateAsync(Departamento departamento)
 {
     if (!await _context.Departamento.AnyAsync(x => x.Id == departamento.Id))
     {
         throw new NotImplementedException();
     }
     try
     {
         _context.Update(departamento);
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new NotImplementedException();
     }
 }
コード例 #2
0
ファイル: OperadorService.cs プロジェクト: EloiJunior/Mesa01
 //Metodo Update
 public async Task UpdateAsync(Operador operador)
 {
     if (!await _context.Operador.AnyAsync(x => x.Id == operador.Id))
     {
         throw new NotFoundException("Id not found");
     }
     try //nesse bloco vamos tentar realizar o update na tabela
     {
         _context.Update(operador);
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException e)           //se ocorrer uma exceção de concorrencia a nivel de acesso a bco de dados, vamos pegar esse erro
     {
         throw new DbConcurrencyException(e.Message); //e vamos apresentar a nivel de serviço a mensagem personalizada, ou nesse caso a propria mensagem que o framework trouxe
     }
 }