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 } }
public bool InCart(ApplicationUser user) { List <CartItem> cartItem = CartItems .Where(i => i.ApplicationUserID == user.Id) .ToList(); return(cartItem.Count != 0); }
public void RemoveItem(Widget widget) { var cartItem = CartItems.Where(x => x.WidgetId == widget.WidgetId).FirstOrDefault(); if (cartItem != null) { CartItems.Remove(widget); } }
public void AddItem(Widget widget) { var cartItem = CartItems.Where(x => x.WidgetId == widget.WidgetId).FirstOrDefault(); if (cartItem == null) { CartItems.Add(widget); } }
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); }
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")); }
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")); }
public Cart RemoveCartItem(Guid itemId) { CartItems = CartItems.Where(y => y.Id != itemId).ToList(); return(this); }
public Cart RemoveCartItem(Guid itemId) { CartItems = CartItems.Where(y => !CartItems.Any(x => x.Id == itemId)).ToList(); return this; }
public decimal CartProductCategoryTotal(ProductCategory productCategory) => CartItems.Where(y => y.Product.ProductCategory == productCategory) .Sum(x => x.UnitPrice * x.Qty);
public decimal CartNonDiscountedPriceExcludingGiftVouchers() => CartItems.Where(y => y.Product.ProductCategory != ProductCategory.GiftVoucher) .Sum(x => x.UnitPrice * x.Qty);