public IActionResult AddToInvoice()
        {
            var     userId       = _manager.GetUserId(HttpContext.User);
            var     shoppingCart = new ShoppingCartRepo(_context, HttpContext);
            var     checkCart    = shoppingCart.GetAll();
            decimal total        = shoppingCart.GetTotal();

            if (userId == null)
            {
                return(RedirectToPage("/Account/Login", new { area = "Identity" }));
            }

            if ((checkCart == null) || (checkCart.Count() == 0))
            {
                return(Redirect("/"));
            }

            Invoice invoiceData = new Invoice
            {
                Created = DateTime.Now,
                Total   = total * 1.07M,
                UserID  = userId
            };

            ViewData["InvoiceData"] = invoiceData;
            if (ModelState.IsValid)
            {
                new InvoicesRepo(_context).CreateInvoice(invoiceData);
                shoppingCart.ClearCart();
                return(RedirectToAction("Index"));
            }
            return(View(invoiceData));
        }
Esempio n. 2
0
        public void ShouldAddAnItemToTheCart()
        {
            ShoppingCartRecord item = new ShoppingCartRecord
            {
                ProductId   = 2,
                Quantity    = 3,
                DateCreated = DateTime.Now,
                CustomerId  = 0
            };

            _repo.Add(item);
            List <ShoppingCartRecord> shoppingCartRecords = _repo.GetAll().ToList();

            Assert.Equal(2, shoppingCartRecords.Count);
            Assert.Equal(2, shoppingCartRecords[0].ProductId);
            Assert.Equal(3, shoppingCartRecords[0].Quantity);
        }