Beispiel #1
0
        public IActionResult Index()
        {
            var userId      = _userManager.GetUserId(User);
            var shoppingBag = _shoppingBagRepository.GetShoppingBag(userId);


            ShoppingBagViewModel shoppingBagViewModel = new ShoppingBagViewModel
            {
                ShoppingItems = shoppingBag.Items,
            };

            if (shoppingBagViewModel.ShoppingItems.Count == 0)
            {
                ViewBag.Empty = "No items added yet.";
            }
            return(View(shoppingBagViewModel));
        }
Beispiel #2
0
        private ShoppingBag GetShoppingBag(string customerId)
        {
            var shoppingBag = _shoppingBagRepository.GetShoppingBag(customerId);

            if (shoppingBag == null)
            {
                var newShoppingBag = new ShoppingBag
                {
                    Customer = _customerRepository.GetCustomer(customerId),
                    Date     = DateTime.Now,
                    Items    = new List <ShoppingItem>()
                };
                shoppingBag = newShoppingBag;
                _shoppingBagRepository.AddItem(shoppingBag);
            }
            return(shoppingBag);
        }