예제 #1
0
        public async Task <ActionResult <BookApiViewModel> > GetBook([FromODataUri] Guid key)
        {
            Book result = await _mediator.Send(new GetBookByIdQuery(key));

            if (result is null)
            {
                return(NotFound(key));
            }

            BookApiViewModel viewModel = BooksApiMapper.MapToApiModel(result);

            return(Ok(viewModel));
        }
예제 #2
0
        public async Task <ActionResult <BookApiViewModel> > Get(Guid id)
        {
            Book result = await _mediator.Send(new GetBookByIdQuery(id));

            if (result is null)
            {
                return(NotFound(id));
            }

            BookApiViewModel viewModel = BooksApiMapper.MapToApiModel(result);

            SingleResult <BookApiViewModel> response =
                new SingleResult <BookApiViewModel>(viewModel);

            return(Ok(response));
        }
        public async Task <ActionResult <BookApiViewModel> > Add(BookAddModel addModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Book result = await _mediator.Send(new AddBookCommand(addModel.Name, (double)addModel.Price));

            if (result is null)
            {
                return(BadRequest());
            }

            BookApiViewModel viewModel = BooksApiMapper.MapToApiModel(result);

            return(Created(Url.RouteUrl("GetBookById", new { id = viewModel.Id }), viewModel));
        }