public async Task <IHttpActionResult> PostBasketItemAsync(Guid basketGuid,
                                                                  [FromBody] BasketItemCreateModel basketItemCreateModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var targetModel =
                    _mappingService.Map <BasketItemCreateModel, Business.Models.BasketItemCreateModel>(
                        basketItemCreateModel);

                //var targetModel = new Business.Models.BasketItemCreateModel
                //{
                //    ProductSku = basketItemCreateModel.ProductSku,
                //    Count = basketItemCreateModel.Count
                //};

                var basketItemGuid = await _basketService.AddBasketItemAsync(basketGuid, targetModel);

                return(Created(Request.RequestUri + "/" + basketItemGuid.ToString("D"), basketItemGuid));
            }
            catch (Exception e)
            {
                LogException(e);
                return(InternalServerError());
            }
        }
Esempio n. 2
0
        public async Task <BasketItem> Handle(CreateBasketItemCommand request, CancellationToken cancellationToken)
        {
            var book = await bookRepository.GetByIdAsync(request.Id);

            return(await basketService.AddBasketItemAsync(book));
        }