예제 #1
0
 public void DoPromotion()
 {
     if (CartItems.Count > 0)
     {
         var subtotal    = CartItems.Where(w => w.isProduct == true).Sum(s => s.Price * s.Quantity);
         var itemFreight = CartItems.FirstOrDefault(f => f.isProduct == false);
         if (itemFreight != null)
         {
             CartItems.Remove(itemFreight);
         }
         #region frieght
         if (subtotal < 200000)
         {
             var frieght = new CartItem();
             frieght.isProduct   = false;
             frieght.Price       = 0;
             frieght.ProductName = "Phí vận chuyển";
             frieght.ProductCode = "FRIEGHTCODE";
             frieght.Quantity    = 1;
             CartItems.Add(frieght);
         }
         else
         {
             var frieght = new CartItem();
             frieght.isProduct   = false;
             frieght.Price       = 0;
             frieght.ProductName = "Phí vận chuyển";
             frieght.ProductCode = "FREEFRIEGHT";
             frieght.Quantity    = 1;
             CartItems.Add(frieght);
         }
         #endregion
     }
 }
예제 #2
0
        public bool InCart(ApplicationUser user)
        {
            List <CartItem> cartItem = CartItems
                                       .Where(i => i.ApplicationUserID == user.Id)
                                       .ToList();

            return(cartItem.Count != 0);
        }
예제 #3
0
        public void RemoveItem(Widget widget)
        {
            var cartItem = CartItems.Where(x => x.WidgetId == widget.WidgetId).FirstOrDefault();

            if (cartItem != null)
            {
                CartItems.Remove(widget);
            }
        }
예제 #4
0
        public void AddItem(Widget widget)
        {
            var cartItem = CartItems.Where(x => x.WidgetId == widget.WidgetId).FirstOrDefault();

            if (cartItem == null)
            {
                CartItems.Add(widget);
            }
        }
예제 #5
0
        public void AddItem(CatalogItem catalogItem, int quantity)
        {
            var cartItem = CartItems
                           .Where(x => x.CatalogItem == catalogItem)
                           .FirstOrDefault();

            if (cartItem == null)
            {
                cartItem = CartItem.Create(catalogItem);
                CartItems.Add(cartItem);
            }

            cartItem.IncreaseQuantity(quantity);
        }
예제 #6
0
        public IActionResult OnPostPlus(int id)
        {
            CartItems = HttpContext.Session.GetObjectFromJson <List <ShoppingCart> >("CartItems").ToList();

            var productiInCart = CartItems.SingleOrDefault(x => x.Product.Id == id);
            var cartItemPlus   = cartBL.PlusCartItem(productiInCart);

            CartItems
            .Where(x => x.Id == id)
            .Select(x => { x.Quantity = cartItemPlus.Quantity; return(x); }).ToList();
            if (cartItemPlus.Quantity == productiInCart.Product.Quantity)
            {
                TempData["Message"] = $"You have reached the limit for {productiInCart.Product.Name}!";
            }
            HttpContext.Session.SetObjectAsJson("CartItems", CartItems);
            CartItems = HttpContext.Session.GetObjectFromJson <List <ShoppingCart> >("CartItems").ToList();
            return(RedirectToPage("./ShoppingCart"));
        }
예제 #7
0
        public IActionResult OnPostMinus(int id)
        {
            CartItems = HttpContext.Session.GetObjectFromJson <List <ShoppingCart> >("CartItems").ToList();
            var productiInCart = CartItems.SingleOrDefault(x => x.Product.Id == id);
            var cartItemMinus  = cartBL.MinusCartItem(productiInCart);

            if (cartItemMinus == null)
            {
                CartItems.Remove(productiInCart);
            }
            else
            {
                CartItems
                .Where(x => x.Id == id)
                .Select(x => { x.Quantity = cartItemMinus.Quantity; return(x); }).ToList();
            }
            HttpContext.Session.SetObjectAsJson("CartItems", CartItems);
            CartItems = HttpContext.Session.GetObjectFromJson <List <ShoppingCart> >("CartItems").ToList();
            return(RedirectToPage("./ShoppingCart"));
        }
예제 #8
0
 public Cart RemoveCartItem(Guid itemId)
 {
     CartItems = CartItems.Where(y => y.Id != itemId).ToList();
     return(this);
 }
예제 #9
0
 public Cart RemoveCartItem(Guid itemId)
 {
   CartItems = CartItems.Where(y => !CartItems.Any(x => x.Id == itemId)).ToList();
   return this;
 }
예제 #10
0
 public decimal CartProductCategoryTotal(ProductCategory productCategory) =>
 CartItems.Where(y => y.Product.ProductCategory == productCategory)
 .Sum(x => x.UnitPrice * x.Qty);
예제 #11
0
 public decimal CartNonDiscountedPriceExcludingGiftVouchers() =>
 CartItems.Where(y => y.Product.ProductCategory != ProductCategory.GiftVoucher)
 .Sum(x => x.UnitPrice * x.Qty);