public ViewResult Index(CartDomainModel cart, string returnUrl)
 {
     return(View(new CartIndexViewModel {
         Cart = cart,
         ReturnUrl = returnUrl
     }));
 }
        //public CartDomainModel GetCart()
        //{
        //    CartDomainModel cart = (CartDomainModel)Session["cart"];

        //    if(cart ==null)
        //    {
        //        cart = new CartDomainModel();
        //        Session["cart"] = cart;
        //    }
        //    return cart;
        //}
        public RedirectToRouteResult AddToCart(CartDomainModel cart, string productId, int quantity, string returnUrl)
        {
            Product p = productDomain.GetById(productId);

            cart.AddCartLine(p, quantity);

            return(RedirectToAction("Index", new { returnUrl }));
        }
 public RedirectToRouteResult RemoveFromCart(CartDomainModel cart, string productId, string returnUrl)
 {
     cart.RemoveCartLine(
         new DataModel.Product
     {
         ID = new Guid(productId)
     }
         );
     return(RedirectToAction("Index", new { returnUrl }));
 }
Beispiel #4
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            CartDomainModel cart = null;

            if (controllerContext.HttpContext.Session != null)
            {
                cart = (CartDomainModel)controllerContext.HttpContext.Session[sessionKey];
            }
            if (cart == null)
            {
                cart = new CartDomainModel();
                if (controllerContext.HttpContext.Session != null)
                {
                    controllerContext.HttpContext.Session[sessionKey] = cart;
                }
            }
            return(cart);
        }
        public ViewResult Checkout(CartDomainModel cart, Order order)
        {
            if (cart.GetCartLines.Count() == 0)
            {
                ModelState.AddModelError("", "Sorry, your cart is empty!");
            }
            if (ModelState.IsValid)
            {
                OrderDomainModel od = new OrderDomainModel();
                order.ID             = Guid.NewGuid();
                order.Status         = 0;
                order.CreateDatetime = DateTime.Now.ToUniversalTime();
                order.UpdateDatetime = DateTime.Now.ToUniversalTime();
                order.OrderItems     = new List <OrderItem>();

                IEnumerable <CartLine> cartLines = cart.GetCartLines;

                foreach (CartLine ca in cartLines)
                {
                    OrderItem oi = new OrderItem();
                    oi.ID = Guid.NewGuid();
                    //oi.OrderID = order.ID;
                    oi.ProductID      = ca.Product.ID;
                    oi.Price          = ca.Product.Price;
                    oi.Quantity       = ca.Quantity;
                    oi.Status         = 0;
                    oi.CreateDatetime = DateTime.Now.ToUniversalTime();
                    oi.UpdateDatetime = DateTime.Now.ToUniversalTime();
                    order.OrderItems.Add(oi);
                }

                od.SaveOrder(order);
                cart.Clear();
                return(View("Completed"));
            }
            else
            {
                return(View(order));
            }


            return(View());
        }