Esempio n. 1
0
 public ActionResult Index()
 {
     cartBusiness = new CartBusiness(Session.GetUserKey());
     var currentCarts = cartBusiness.GetCurrentCarts();
     return View(new CartViewModel
     {
         GrandTotal = CartBusiness.CalculateGrandTotal(currentCarts.AsQueryable()),
         CartDetailList = cartBusiness.GenerateCartDetailList(currentCarts)
     });
 }
Esempio n. 2
0
 public void RemoveFromCart(int Id)
 {
     cartBusiness = new CartBusiness(Session.GetUserKey());
     try
     {
         cartBusiness.RemoveFromCart(Id);
     }
     catch( InvalidOperationException)
     {
         var ex = new HttpException(404, "");
         ex.Data["ErrType"] = Globals.ERRTYPES.OTHER;
         throw ex;
     }
 }
Esempio n. 3
0
        public void AddToCart(int ProductId, decimal UnitPrice)
        {
            cartBusiness = new CartBusiness(Session.GetUserKey());

            if (UnitPrice != new ProductBusiness().GetPrice(ProductId))
            {
                throw new HttpException(400, "");
            }

            try
            {
                cartBusiness.AddToCart(ProductId);
            }
            catch(InvalidOperationException)
            {
                throw new HttpException(404, "");
            }
        }
        public ActionResult Shipping(Shipping Shipping)
        {
            var cartBusiness = new CartBusiness { UserKey = Session.GetUserKey() };
            if (cartBusiness.GetCurrentCartCount() <= 0)
            {
                var ex = new HttpException(400, "");
                ex.Data["ErrType"] = Globals.ERRTYPES.CART_CARTEMPTY;
                throw ex;
            }

            if (ModelState.IsValid)
            {
                var orderBusiness = new OrderBusiness();
                orderBusiness.CreateOrder(cartBusiness.UserKey, cartBusiness.GetCurrentCarts(), Shipping);

                return RedirectToAction("Checkout");
            }
            else
            {
                return View(Shipping);
            }
        }