Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have two tables in my database, one of departments and the other of employees, and an employee can only belong to one department so
I have two tables in my database, one of departments and the other of employees, and an employee can only belong to one department so there is a departmentId in the employee that works as a foreign key of the department table referencing the id of that table, but when my api adds an employee when filling in departmentId, the value I filled in changes and the next value that has available in the id of the departments table is placed
the code i was using in the api was:
public async Task CreateFuncionarioFuncionario novoFuncionario
ServiceResponse serviceResponse new ServiceResponse;
try
if novoFuncionario null
serviceResponse.Dados null;
serviceResponse.Mensagem "Informar Dados";
serviceResponse.Sucesso false;
return serviceResponse;
context.AddnovoFuncionario;
await context.SaveChangesAsync;
novoFuncionario await context.Funcionarios.FindAsyncnovoFuncionarioId;
serviceResponse.Dados context.Funcionarios.ToList;
catch Exception ex
serviceResponse.Mensagem exMessage;
serviceResponse.Sucesso false;
return serviceResponse;
i was inserting in api using:
id:
"nome": Joo
"foto": "string",
rg:
"departamentoId":
"departamento":
id:
"nome": "string",
"sigla": "string"
and the response was:
Response body
"dados":
id:
"nome": Joo
"foto": "string",
rg:
"departamentoId":
"departamento":
id:
"nome": "string",
"sigla": "string"
"mensagem":
"sucesso": true
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started