Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateLoanStatusToApproved(long id)
        {
            var reservation = await reservationService.FindById(id);

            if (reservation == null)
            {
                return(NotFound($"Nenhuma reserva encontrada com o ID: {id}."));
            }
            try
            {
                var book = await bookService.FindById(reservation.BookId);

                if (book == null)
                {
                    return(NotFound($"Nenhum livro encontrado com o ID: {reservation.BookId}."));
                }
                await reservationService.ApprovedReservation(reservation, book);

                return(Ok());
            }
            catch (ReservationApprovedException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (InvalidOperationException ex)
            {
                return(BadRequest(ex.Message));
            }
        }