예제 #1
0
        public CartViewModel GetCartWithTruePrice()
        {
            CartViewModel cart = GetCart();

            for (int i = 0; i < cart.ListItem.Count; i++)
            {
                CartItemViewModel cartItem = cart.ListItem[i];
                if (cartItem != null)
                {
                    Book book = db.Books.Where(q => q.DeletedAt == null && q.Id == cartItem.Id).FirstOrDefault();
                    if (book != null)
                    {
                        cartItem.Name           = book.Name;
                        cartItem.Price          = book.Price;
                        cartItem.Discount       = book.Discount;
                        cartItem.RemainQuantity = book.Quantity;
                    }
                    else
                    {
                        cart.ListItem.RemoveAt(i);
                    }
                }
            }

            cart.RecalculateTotalAndQuantity();

            return(cart);
        }