public async Task <Response <Exception, AppUnit> > Handle(RentalFinishCommand request, CancellationToken cancellationToken) { // Retorna a lista virtual dos filmes var rentalCallback = await _rentalRepository.GetByIdAsync(request.RentalId); // Verifica algum erro if (rentalCallback.HasError) { return(rentalCallback.Error); } var rental = rentalCallback.Success; // Finaliza o aluguel rental.FinishRental(); // Atualiza o aluguel var newRentalCallback = await _rentalRepository.UpdateAsync(rental); // Verifica algum erro if (newRentalCallback.HasError) { return(newRentalCallback.Error); } // Retorna ok return(AppUnit.Successful); }
public async Task <IActionResult> FinishRental([FromBody] RentalFinishCommand rentalFinishCommand) { return(HandleCommand(await _mediator.Send(rentalFinishCommand))); }