示例#1
0
        public async Task <IActionResult> Index()
        {
            ViewBag.Loggedin   = HttpContext.Session.GetInt32("authenticated").HasValue;
            this.cartHelpers   = new Helpers.CartHelpers(this.HttpContext.Session);
            ViewBag.Categories = await categoryModel.GetAll();

            var cart = cartHelpers.GetCart();

            return(View(cart));
        }
        public async Task <IActionResult> Checkout()
        {
            ViewBag.Loggedin = HttpContext.Session.GetInt32("authenticated").HasValue;
            if (!HttpContext.Session.GetInt32("authenticated").HasValue)
            {
                return(new RedirectToActionResult("index", "login", null));
            }

            cartHelpers = new Helpers.CartHelpers(HttpContext.Session);
            var cart = cartHelpers.GetCart();

            if (cart.CartLines.Count == 0)
            {
                return(new RedirectToActionResult("index", "cart", null));
            }


            var user = await userModel.GetUser(HttpContext.Session.GetInt32("authenticated").Value);

            await orderModel.RegisterOrder(user, cart);

            return(View());
        }