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);
        }
Esempio n. 2
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);
        }