Beispiel #1
0
        public void AddToCart(Book book)
        {
            // Get the matching cart and book instances
            var cartItem = storeDB.Carts.SingleOrDefault(
                c => c.CartId == ShoppingCartId
                    && c.BookId == book.Id);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new Cart
                {
                    BookId = book.Id,
                    CartId = ShoppingCartId,
                    Count = 1,
                    DateCreated = DateTime.Now
                };

                storeDB.Carts.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart, then add one to the quantity
                cartItem.Count++;
            }

            // Save changes
            storeDB.SaveChanges();
        }
Beispiel #2
0
 private Cart getCart()
 {
     Cart cart = (Cart) Session["Cart"];
     if (cart == null) {
         cart = new Cart();
         Session["Cart"] = cart;
     }
     return cart;
 }
Beispiel #3
0
        public void AddToCart(Ksiazka ksiazka)
        {
            var cartItem = storeDB.Carty.SingleOrDefault(
                c => c.CartId == ShoppingCartId
                && c.KsiazkaId == ksiazka.KsiazkaId
                );
            if (cartItem == null)
            {
                cartItem = new Cart
                {
                    KsiazkaId = ksiazka.KsiazkaId,
                    CartId = ShoppingCartId,
                    Ilosc = 1,
                    DateCreated = DateTime.Now

                };
                storeDB.Carty.Add(cartItem);
            }
            else
            {
                cartItem.Ilosc++;
            }
            storeDB.SaveChanges();
        }