Ejemplo n.º 1
0
        /// <summary>
        /// To remove book from the cart
        /// </summary>
        /// <param name="bookCartItem">book cart item</param>
        public void RemoveBook(BookCartItem bookCartItem)
        {
            if (bookCartItem != null && bookCartItem.Book != null)
            {
                var existingBookCartItem = BookCartItems.FirstOrDefault(b => b.Book != null && b.Book.ID == bookCartItem.Book.ID);
                if (existingBookCartItem != null)
                {
                    BookCartItems.Remove(existingBookCartItem);
                }

                UpdateTotalPrice();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// To Update the book cart item quantity
        /// </summary>
        /// <param name="bookCartItem">book cart item</param>
        /// <param name="quantity">number of quantity</param>
        public void UpdateQuantity(BookCartItem bookCartItem, int quantity)
        {
            if (bookCartItem != null && bookCartItem.Book != null)
            {
                var existingBookCartItem = BookCartItems.FirstOrDefault(b => b.Book != null && b.Book.ID == bookCartItem.Book.ID);
                if (existingBookCartItem != null)
                {
                    existingBookCartItem.Quantity = quantity;
                }

                UpdateTotalPrice();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// To add book to the cart
        /// </summary>
        /// <param name="bookCartItem">book cart item</param>
        public void AddBook(BookCartItem bookCartItem)
        {
            if (bookCartItem != null && bookCartItem.Book != null)
            {
                var existingBookCartItem = BookCartItems.FirstOrDefault(b => b.Book != null && b.Book.ID == bookCartItem.Book.ID);
                if (existingBookCartItem == null)
                {
                    BookCartItems.Add(bookCartItem);
                }
                else
                {
                    existingBookCartItem.Quantity += bookCartItem.Quantity;
                }

                UpdateTotalPrice();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// To empty the cart
        /// </summary>
        public void Clear()
        {
            BookCartItems.Clear();

            UpdateTotalPrice();
        }