Esempio n. 1
0
        public async Task <IActionResult> Items()
        {
            var shoppingCartItems = _shoppingCartManager.GetItems(HttpContext.Session.GetShoppingCartId()).ToList();

            var cartItemServiceModels = await _cartItemsService.GetCartsItemsServiceModelAsync(shoppingCartItems);

            return(Ok(cartItemServiceModels));
        }
        public IActionResult Items()
        {
            var shoppingCartId = this.HttpContext.Session.GetShoppingCartId();

            var items = shoppingCartManager.GetItems(shoppingCartId);

            var itemsIds = items.Select(i => i.ProductId);

            var cartItems = this.db
                            .Products
                            .Where(p => itemsIds.Contains(p.Id))
                            .Select(p => new ShoppingCartItemsViewModel
            {
                Id       = p.Id,
                Title    = p.Title,
                Price    = p.Price,
                Quantity = items.Where(i => i.ProductId == p.Id).Select(i => i.Quantity).FirstOrDefault()
            })
                            .ToList();

            return(View(cartItems));
        }