Exemplo n.º 1
0
        public ViewResult Checkout(Cart cart)
        {
            var client = clientLogic.GetClientByEmail(User.Identity.Name);
            if (cart.Lines.Count() == 0)
            {
                ModelState.AddModelError("", "Sorry, your cart is empty.");
            }

            if (ModelState.IsValid)
            {

                Sale sale= Sale.CreateSale(0,client.ClientId,cart.ComputeTotalValue(),DateTime.Today, client.ShippingAddressId);
                /*
                sale.Client = client;
                sale.ShippingAddress=client.ShippingAddress;
                sale.SaleTotal=cart.ComputeTotalValue();
                sale.Date = DateTime.Today;*/
                saleLogic.AddSale(sale);
                ICollection<SaleDetail> icollection = new List<SaleDetail>();

                foreach (var line in cart.Lines)
                {
                    SaleDetail saledetail = SaleDetail.CreateSaleDetail(sale.SaleId,line.Product.ItemId, line.Quantity);
                    saledetail.Item = line.Product;
                    saledetail.Quantity = line.Quantity;
                    icollection.Add(saledetail);
                }

                saleLogic.AddSale(icollection);
                cart.Clear();
                return View("Completed");
            }

            return View(client);
        }
Exemplo n.º 2
0
        public ViewResult Index(Cart cart, string returnUrl)
        {
            var cartIndexViewModel = new CartIndexViewModel()
            {
                Cart = cart,
                ReturnUrl = returnUrl
            };

            return View(cartIndexViewModel);
        }
Exemplo n.º 3
0
        public RedirectToRouteResult AddToCart(Cart cart, int productId, string returnUrl)
        {
            var product = itemLogic.GetItemByID(productId);

            if (product != null)
            {
                cart.AddItem(product, 1);
            }

            return RedirectToAction("Index", new { returnUrl });
        }
Exemplo n.º 4
0
        public RedirectToRouteResult RemoveFromCart(Cart cart, int productId, string returnUrl)
        {
            var productLine = cart.Lines
                .FirstOrDefault(prod => prod.Product.ItemId == productId);

            if (productLine != null)
            {
                cart.RemoveItem(productLine.Product);
            }

            return RedirectToAction("Index", new { returnUrl });
        }
Exemplo n.º 5
0
        public RedirectToRouteResult AddToCart(Cart cart, int productId, string returnUrl)
        {
            var product = _productRepository.Products
                .FirstOrDefault(prod => prod.ItemId == productId);

            if (product != null)
            {
                cart.AddItem(product, 1);
            }

            return RedirectToAction("Index", new { returnUrl });
        }
Exemplo n.º 6
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var cart = (Cart)controllerContext.HttpContext.Session[SessionKey];

            if (cart == null)
            {
                cart = new Cart();
                controllerContext.HttpContext.Session[SessionKey] = cart;
            }

            return cart;
        }
Exemplo n.º 7
0
        public ViewResult Checkout(Cart cart, Address shippingDetails)
        {
            if (cart.Lines.Count() == 0)
            {
                ModelState.AddModelError("", "Sorry, your cart is empty.");
            }

            if (ModelState.IsValid)
            {
                _orderProcessor.ProcessOrder(cart, shippingDetails);
                cart.Clear();
                return View("Completed");
            }

            return View(shippingDetails);
        }
Exemplo n.º 8
0
 public ViewResult Summary(Cart cart)
 {
     return View(cart);
 }