public async Task <ActionResult <OrderReadDto> > Get([FromRoute] int id) { OrderReadDto order = _mapper.Map <OrderReadDto>(await _orderService.GetByIdAsync(id)); if (order == null) { throw new ApiException(MessagesResource.ORDER_NOT_FOUND, 404); } return(Ok(order)); }
public async Task <ActionResult <OrderReadDto> > Post([FromBody] OrderCreateDto orderCreateDto) { orderCreateDto.ReaderId = User.GetUserId(); OrderReadDto newOrder = _mapper.Map <OrderReadDto>( await _orderService.AddAsync(_mapper.Map <Order>(orderCreateDto)) ); Book book = await _bookService.ToggleAvailability(newOrder.BookId); await _notificationsService.OrderBook(new BookDto { Author = (await _bookService.GetByIdAsync(book.Id)).Author.Name, Title = book.Title }); return(CreatedAtAction("Get", new { id = newOrder.Id }, newOrder)); }