public async Task <ActionResult> PutFornecedorAsync(long id, Fornecedor fornecedor) { try { if (id != fornecedor.Id) { throw new Exception("Os parâmetros de Id's não coincidiram."); } Empresa empresa = await _context.Empresa.FindAsync(fornecedor.EmpresaFK); if (empresa == null) { throw new Exception("Empresa inexistente no sistema."); } _fornecedorService.ValidarFornecedor(fornecedor, empresa); _context.Entry(fornecedor).State = EntityState.Modified; await _context.SaveChangesAsync(); return(NoContent()); } catch (Exception erro) { if (!FornecedorExiste(id)) { throw new Exception("Falha ao atualizar o cadastro do Fornecedor. Erro: Parâmetro ID não existente."); } throw new Exception(string.Format("Falha ao atualizar o cadastro do Fornecedor. Erro: \r\n{0}", erro.Message)); } }