Пример #1
0
        public ViewResult Index()
        {
            var items = _shoppingCart.GetOrderItems(); // requesting for all order items from database

            _shoppingCart.OrderItems = items;

            var shoppingCartViewModel = new ShoppingCartViewModel        // creating a new viewmodel which contains
            {
                ShoppingCart      = _shoppingCart,                       // the shopping cart
                ShoppingCartTotal = _shoppingCart.GetShoppingCartTotal() // and total
            };

            return(View(shoppingCartViewModel)); // and passing this viewmodel to the view
        }
        public IViewComponentResult Invoke()           // the same as the Index method of the ShoppingCartController
        {
            var items = _shoppingCart.GetOrderItems(); // requesting for all order items from database

            //var items = new List<OrderItem> { new OrderItem(), new OrderItem() }; // just a mock data for testing of the front page glyph thet should show 2 items in my basket
            _shoppingCart.OrderItems = items;

            var shoppingCartViewModel = new ShoppingCartViewModel        // creating a new viewmodel which contains
            {
                ShoppingCart      = _shoppingCart,                       // the shopping cart
                ShoppingCartTotal = _shoppingCart.GetShoppingCartTotal() // and total
            };

            return(View(shoppingCartViewModel)); // and passing this viewmodel to the view
        }