Ejemplo n.º 1
0
        async Task <BasketIndexViewModel> GetCurrentUserBasket()
        {
            string userId = _userService.GetUserName(HttpContext, Request.Cookies, Response.Cookies);

            BasketIndexViewModel b = await _basketService.GetOrCreateBasketForUser(userId);

            return(b);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> RemoveItem(int productId)
        {
            BasketIndexViewModel basketViewModel = await GetCurrentUserBasket();

            BasketRemoveItemResponse response =
                await _basketService.RemoveBasketItem(basketViewModel.Id, productId);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public async Task <IViewComponentResult> InvokeAsync(string userName)
        {
            BasketComponentViewModel vm     = new BasketComponentViewModel();
            BasketIndexViewModel     basket = await GetBasketViewModelAsync();

            vm.ItemsCount = basket.BasketItems.Sum(i => i.Quantity);

            return(View(vm));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UpdateItem(Dictionary <int, int> items)
        {
            if (items == null)
            {
                return(RedirectToAction("Index", "Products"));
            }

            BasketIndexViewModel basketViewModel = await GetCurrentUserBasket();

            BasketUpdateResponse response = await _basketService.UpdateBasketItem(basketViewModel.Id, items);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> AddToBasket(ProductItemViewModel productDetails)
        {
            if (productDetails?.Id == null)
            {
                return(RedirectToAction("Index", "Products"));
            }

            BasketIndexViewModel basketViewModel = await GetCurrentUserBasket();

            BasketAddItemResponse response = await _basketService.AddItemToBasket(basketViewModel.Id, productDetails.Id, productDetails.Price, 1);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
        //удаление товара из корзину пользователя
        public void Can_View_Basket_Contents()
        {
            //Организация
            Basket           basket = new Basket();
            BasketController target = new BasketController(null, null);

            //Действия
            BasketIndexViewModel result = (BasketIndexViewModel)target.Index(basket, "myUrl").ViewData.Model;

            //Утверждение
            Assert.AreSame(result.Basket, basket);
            Assert.AreEqual(result.ReturnUrl, "myUrl");
        }
Ejemplo n.º 7
0
        private BasketIndexViewModel GetViewModelFromBasket(BasketModelResponse basket)
        {
            BasketIndexViewModel model = new BasketIndexViewModel();

            model.Id          = basket.BasketId;
            model.UserId      = basket.UserId;
            model.BasketItems = basket.Items.Select(i =>
            {
                BasketItemViewModel itemModel = new BasketItemViewModel()
                {
                    UnitPrice     = i.Price,
                    Quantity      = i.Quantity,
                    ProductItemId = i.ProductId,
                    ProductName   = i.ProductName
                };

                return(itemModel);
            }).ToList();

            return(model);
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> Index()
        {
            BasketIndexViewModel b = await GetCurrentUserBasket();

            return(View(b));
        }