3
respostas

[Dúvida] Dùvida na hora de upar no postman

Nahora de fazer o put, da status 500

System.NotImplementedException: The method or operation is not implemented. at FilmesApi.Data.FilmeContext.SaveChances() in C:\Users\vinyz\Documents\Visual Studio 2022\FilmesAPI\FilmesApi\Data\FilmeContext.cs:line 18 at FilmesApi.Controllers.FilmeController.AtualizaFilme(Int32 id, UpdateFilmeDto filmeDto) in C:\Users\vinyz\Documents\Visual Studio 2022\FilmesAPI\FilmesApi\Controllers\FilmeController.cs:line 76 at lambda_method2(Closure , Object , Object[] ) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

HEADERS

Accept: / Connection: keep-alive Host: localhost:7038 User-Agent: PostmanRuntime/7.30.0 Accept-Encoding: gzip, deflate, br Content-Type: application/json Content-Length: 74 Postman-Token: 6df976cc-ae09-46a3-8b2f-d0069fe9cd8e

3 respostas

Bom dia Vinycius! tudo bem?

Parece que está acontecendo um erro quando você tenta fazer um pedido PUT para atualizar um filme. A mensagem de erro está dizendo que uma exceção do tipo System.NotImplementedException foi lançada, o que significa que o código está tentando chamar um método que ainda não foi implementado. A pilha de rastreamento mostra que a exceção ocorreu no método FilmeContext.SaveChances() na linha 18 e no método FilmeController.AtualizaFilme(Int32 id, UpdateFilmeDto filmeDto) na linha 76. Aparentemente precisa ser implementado o método SaveChanges() na classe FilmeContext também.

ᅠCaso este post tenha lhe ajudado, por favor, marcar como solucionado ✓. Bons Estudos!ᅠ

Boa tarde, Acabei solucionando esse problema. Eu tinha escrito o método de forma eerrada, agora já resolvi este problema. Pórem, assim que resolvi esse veio outro.

System.InvalidOperationException: The property 'Filme.Id' is part of a key and so cannot be modified or marked as modified. To change the principal of an existing entity with an identifying foreign key, first delete the dependent and invoke 'SaveChanges', and then associate the dependent with the new principal.

at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetPropertyModified(IProperty property, Boolean changeState, Boolean isModified, Boolean isConceptualNull, Boolean acceptChanges) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectValueChange(InternalEntityEntry entry, IProperty property) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.LocalDetectChanges(InternalEntityEntry entry) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ChangeDetector.DetectChanges(IStateManager stateManager) at Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker.DetectChanges() at Microsoft.EntityFrameworkCore.DbContext.TryDetectChanges() at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess) at Microsoft.EntityFrameworkCore.DbContext.SaveChanges() at FilmesApi.Controllers.FilmeController.AtualizaFilme(Int32 id, UpdateFilmeDto filmeDto) in C:\Users\vinyz\Documents\Visual Studio 2022\FilmesAPI\FilmesApi\Controllers\FilmeController.cs:line 78 at lambda_method2(Closure , Object , Object[] ) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Assim está meu código e não achei nada de errôneo.
 [HttpPut("{id}")]
public IActionResult AtualizaFilme( int id, 
    [FromBody] UpdateFilmeDto filmeDto )
{
    var filme = _context.Filmes.FirstOrDefault(
        filme => filme.Id == id);
    if (filme == null) return NotFound();
    _mapper.Map(filmeDto, filme);
    _context.SaveChanges();   -->** line 78**
        return NoContent();
}

// codigo do professor

    [HttpPut("{id}")]
public IActionResult AtualizaFilme(int id,
    [FromBody] UpdateFilmeDto filmeDto)
{
    var filme = _context.Filmes.FirstOrDefault(
        filme => filme.Id == id);
    if (filme == null) return NotFound();
    _mapper.Map(filmeDto, filme);
    _context.SaveChanges();
            return NoContent();
    }

Bom dia Vinycius, tudo bom?

Caramarada verifique suas entidades (Filme e FilmeDTO) para ver as propriedades Id, se puder posta o git do seu projeto aqui também que damos uma olhada! blz?

Abraços e bons estudos 😄


Caso este post tenha lhe ajudado, por favor, marcar como solucionado ✓. Bons Estudos!