Exemplo n.º 1
0
        public async Task <IActionResult> Index(string code = null)
        {
            await CheckUserCounterData();

            string idUsuario = GetUserId();

            CustomerBasket basket;

            if (!string.IsNullOrWhiteSpace(code))
            {
                var product = await catalogService.GetProduct(code);

                if (product == null)
                {
                    return(RedirectToAction("ProductNotFound", "Basket", code));
                }

                BasketItem itemBasket = new BasketItem(product.Code, product.Code, product.Name, product.Price, 1);
                basket = basketService.AddItem(idUsuario, itemBasket);
            }
            else
            {
                basket = basketService.GetBasket(idUsuario);
            }
            await CheckUserCounterData();

            return(View(basket));
        }
        public async Task <IActionResult> AddItem(int itemId)
        {
            string userId = User.Identity.Name;
            await _basketService.AddItem(userId, itemId);

            return(RedirectToAction("Index", "Basket"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Index(string code = null)
        {
            await CheckUserCounterData();

            try
            {
                string idUsuario = GetUserId();

                CustomerBasket basket;
                if (!string.IsNullOrWhiteSpace(code))
                {
                    var product = await catalogService.GetProduct(code);

                    if (product == null)
                    {
                        return(RedirectToAction("ProductNotFound", "Basket", code));
                    }

                    BasketItem itemBasket = new BasketItem(product.Code, product.Code, product.Name, product.Price, 1, product.ImageURL);
                    basket = await basketService.AddItem(idUsuario, itemBasket);
                }
                else
                {
                    basket = await basketService.GetBasket(idUsuario);
                }
                await CheckUserCounterData();

                return(View(basket));
            }
            catch (BrokenCircuitException e)
            {
                logger.LogError(e, e.Message);
                HandleBrokenCircuitException(catalogService);
            }
            catch (Exception e)
            {
                logger.LogError(e, e.Message);
                HandleException();
            }
            return(View());
        }
Exemplo n.º 4
0
        public async Task <ActionResult <BasketViewModel> > Add(long bookId)
        {
            var book = repoBook.Get(bookId);

            if (book != null)
            {
                await basketService.AddItem(book, 1);
            }

            return(mapper
                   .Map <IBasketService, BasketViewModel>(basketService));
        }
Exemplo n.º 5
0
        public List <BasketDTO> Post([FromBody] AddedItemDTO addedItem)
        {
            try
            {
                var result = _basketService.AddItem(addedItem);

                return(result);
            }
            catch (Exception ex)
            {
                throw new AppException(ex.Message);
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> AddItem(CreateBasketItemsDTO item, long userId)
        {
            var dto = await service.AddItem(item, userId);

            if (dto != null)
            {
                return(Ok(dto));
            }
            else
            {
                return(BadRequest());
            }
        }
        public void AddItem_should_add_item_to_store()
        {
            var basket = new Basket(_testCustomerId, new List <Item>());

            _mockBasketStore.Setup(x => x.FindByCustomerId(_testCustomerId))
            .Returns(basket);
            _mockBasketStore.Setup(x => x.AddItem(_testCustomerId, It.IsAny <Item>()))
            .Verifiable();

            var result = _sut.AddItem(_testCustomerId, new Item("item1", 1));

            _mockBasketStore.Verify(x => x.FindByCustomerId(_testCustomerId), Times.Once);
            _mockBasketStore.Verify(x => x.AddItem(_testCustomerId, It.IsAny <Item>()), Times.Once);
        }
Exemplo n.º 8
0
        public async Task <IActionResult> AddUserBasketItem([FromBody] UserBasket userBasket)
        {
            await basketService.AddItem(userBasket);

            return(Ok());
        }
Exemplo n.º 9
0
        public async Task <ResponseModel> AddBasket([FromQuery] int customerId, [FromQuery] int productId, [FromQuery] int amount)
        {
            var response = await _basketService.AddItem(customerId, productId, amount);

            return(response);
        }
        public IActionResult AddItem(string customerId, [FromBody] AddItemRequest request)
        {
            var basket = _basketService.AddItem(customerId, new Item(request.ItemId, request.Quantity));

            return(new OkObjectResult(basket));
        }