Пример #1
0
        public ActionResult AddToCart(int?id, int?quantity)
        {
            var user = User.Identity.Name;

            if (User.Identity.IsAuthenticated)
            {
                Book     book     = db.Books.Where(x => x.BookID == id).First();
                Customer customer = db.Customers.Where(x => x.Username == user).First();
                Shopping cart     = db.Shoppings.Where(x => x.CustomerID == customer.CustomerID).First();
                // Cart_Book cb = db.Cart_Book.Where(x => x.CartID == cart.CartID && x.BookID == id).First();
                if (quantity > book.Inventory)
                {
                    quantity = book.Inventory;
                }
                db.usp_AddBookToCart(cart.CartID, book.BookID, customer.CustomerID, quantity);
            }
            else
            {
                return(RedirectToAction("Login", "Account", null));
            }

            return(RedirectToAction("Index", "Book", null));
        }