Esse erro é meio estranho, porque ele não me dá o retorno do Json com a criação e o status 200 ok, porém a Sessão é criada. Ao consultar a Sessão o Json vem normalmente.
Metodo de criação.
[HttpPost]
public IActionResult AdicionaSessao(CreateSessaoDto dto)
{
Sessao sessao = _mapper.Map<Sessao>(dto);
_context.Sessoes.Add(sessao);
_context.SaveChanges();
return CreatedAtAction(nameof(RecuperaSessaoPorId), new { id = sessao.Id, sessao });
}
Metodo de Recuperação
[HttpGet("{id}")]
public IActionResult RecuperaSessaoPorId(int id)
{
Sessao sessao = _context.Sessoes.FirstOrDefault(sessao => sessao.Id == id);
if (sessao != null)
{
ReadSessaoDto sessaoDto = _mapper.Map<ReadSessaoDto>(sessao);
return Ok(sessaoDto);
}
return NotFound();
}
Erro no PostMan (Só achei a descrição do erro no PostMan)
System.InvalidOperationException: No route matches the supplied values.
at Microsoft.AspNetCore.Mvc.CreatedAtActionResult.OnFormatting(ActionContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor.ExecuteAsyncCore(ActionContext context, ObjectResult result, Type objectType, Object value)
at Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor.ExecuteAsync(ActionContext context, ObjectResult result)
at Microsoft.AspNetCore.Mvc.ObjectResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultAsync(IActionResult result)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
HEADERS
=======
Connection: keep-alive
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip, deflate, br
Host: localhost:5001
Referer: http://localhost:5000/sessao/
User-Agent: PostmanRuntime/7.29.2
Content-Length: 96
Postman-Token: c0fad2b4-78d1-49bc-b715-bf9eb57c3339
PostMan com o retorno da Sessão criada.
Json do retorno do Get.
{
"id": 1,
"cinema": {
"id": 1,
"nome": "CineZika",
"endereco": {
"id": 1,
"logradouro": "Avenida dos Zikas",
"bairro": "Jd. Villas dos Zikis",
"numero": 305
},
"enderecoId": 1,
"gerente": {
"id": 1,
"nome": "Igor Zika"
},
"gerenteId": 1
},
"filme": {
"id": 1,
"titulo": "Filme Zika",
"duracao": 120,
"diretor": "Zika Jackson",
"genero": "Avantura",
"classificacaoEtaria": 14
},
"horarioDeEncerramento": "2022-01-01T21:00:00",
"horarioDeInicio": "2022-01-01T19:00:00"
}