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 IList <CartItem> Remove(string productId, int quantity, out IList <CartItemDetail> shoppingCartItemDetailsRemoved) { IList <CartItem> itemRemoves = new List <CartItem>(); shoppingCartItemDetailsRemoved = new List <CartItemDetail>(); bool isRemove = false; for (int i = 0; i < quantity; i++) { var item = CartItems.FirstOrDefault(p => p.ProductId == productId); if (item != null) { CartItems.Remove(item); isRemove = true; itemRemoves.Add(item); } } if (isRemove) { var item = CartItems.FirstOrDefault(p => p.ProductId == productId); if (item == null) { if (CartItemDetails.ContainsKey(productId)) { shoppingCartItemDetailsRemoved.Add(CartItemDetails[productId]); CartItemDetails.Remove(productId); } } } RemoveItemEvent(itemRemoves, shoppingCartItemDetailsRemoved); return(itemRemoves); }
public void RemoveCartItemWithProduct(int productId) { var removedItem = CartItems.FirstOrDefault(x => x.ProductId == productId); if (removedItem != null) { CartItems.Remove(removedItem); } }
public void RemoveCartItem(int cartItemId) { var removedItem = CartItems.FirstOrDefault(x => x.Id == cartItemId); if (removedItem != null) { CartItems.Remove(removedItem); } }
public override void Add(CartItem cartItem) { var res = CartItems.FirstOrDefault(item => item.Product.ProductId == cartItem.Product.ProductId); if (res == null) { base.Add(cartItem); return; } throw new ArgumentException("This product has already been added"); }
public Cart AccumulateCartItemQuantity(Guid cartItemId, int quantity) { var cartItem = CartItems.FirstOrDefault(x => x.Id == cartItemId); if (cartItem == null) { throw new DomainException($"Couldn't find cart item #{cartItemId}"); } cartItem.AccumulateQuantity(quantity); return(this); }
public override void Add(CartItem cartItem) { var res = CartItems.FirstOrDefault(item => item.Product.ProductId == cartItem.Product.ProductId); if (res == null) { base.Add(cartItem); return; } res.Quantity += cartItem.Quantity; }
public bool ChangeProductQuantity(int productId, int quantity) { CartItem existingItem = CartItems.FirstOrDefault(p => p.ProductId.Equals(productId)); if (existingItem == null) { return(false); } existingItem.Quantity = quantity; return(true); }
public void AddOrUpdateItem(CartItem item) { var existingItem = CartItems.FirstOrDefault(ci => ci.ProductId == item.ProductId); if (existingItem == null) { CartItems.Add(item); } else { existingItem.Quantity += item.Quantity; } }
public decimal ExpectedQtyForPart(int partId) { return(CartItems.FirstOrDefault(ci => ci.Part.Id == partId).OpenQty); //int qty = 0; //foreach (Shipment shipment in Shipments) //{ // if (shipment.Part.Id == partId) // qty += shipment.Qty; //} //return LineItemQtyForPart(partId) - qty; }
public void SubtractProduct(Product product) { var cartItem = CartItems.FirstOrDefault(x => x.Product == product); if (cartItem.Quantity <= 1) { CartItems.Remove(cartItem); } else { cartItem.TotalPrice -= cartItem.Product.Price; cartItem.Quantity--; } RefreshTotalAmount(); }
public ActionResult Delete(int id) { Thread.Sleep(1000); CartItem inCartItem = CartItems.FirstOrDefault(item => item.Id == id); if (inCartItem != null) { CartItems.Remove(inCartItem); return(new HttpStatusCodeResult(200, "資料已刪除")); } else { return(HttpNotFound()); } }
public ActionResult Delete(int id) { Thread.Sleep(1000); CartItem inCartItem = CartItems.FirstOrDefault(item => item.Id == id); if (inCartItem != null) { CartItems.Remove(inCartItem); return(RedirectToAction("Index")); } else { return(HttpNotFound()); } }
public void AddCart(Product product) { var existingProduct = CartItems.FirstOrDefault(i => i.ProductId == product.Id); if (existingProduct != null) { existingProduct.Quantity++; } else { var item = new CartItem { Product = product, Quantity = 1 }; CartItems.Add(item); } }
public void AddProduct(Product product, int quantity) { CartItem existingItem = CartItems.FirstOrDefault(p => p.ProductId.Equals(product.Id)); if (existingItem == null) { var item = new CartItem { Product = product, ProductId = product.Id, Quantity = quantity, CartId = Id }; CartItems.Add(item); } else { existingItem.Quantity += quantity; } }
public ActionResult AddToCart(int albumId) { CartItem inCartItem = CartItems.FirstOrDefault(item => item.Album.Id == albumId); if (inCartItem != null) { inCartItem.Amount = ++inCartItem.Amount; } else { var item = new CartItem { Id = CartItems.Count() > 0?CartItems.Last().Id + 1:1, Album = db.Albums.Find(albumId), Amount = 1 }; CartItems.Add(item); } return(RedirectToAction("Index")); }
public decimal BasketProductPrice(int pid, string lang = "fa", bool withDiscount = true, bool containQuantity = true, int cvrt = 1000) { var product = CartItems.FirstOrDefault(x => x.Product.P_Id == pid && x.PrintAble == false); if (product == null) { return(0); } int quantity = (containQuantity) ? product.Quantity : 1; decimal result = 0; if (withDiscount) { result = (((PriceModel)product.Product.PriceModel).PdfPrice * quantity); } else { result = (((PriceModel)product.Product.PriceModel).PdfPriceWithOutDiscount) * quantity; } return((lang == "fa") ? result : result / cvrt); }
public void AddProduct(Product product) { var cartItem = CartItems.FirstOrDefault(x => x.Product.Id == product.Id); if (cartItem == null) { CartItem newCartItem = new CartItem { Quantity = 1, Product = product }; newCartItem.TotalPrice += newCartItem.Product.Price; CartItems.Add(newCartItem); } else { cartItem.TotalPrice += cartItem.Product.Price; cartItem.Quantity++; } RefreshTotalAmount(); }
public void RemoveProduct(int productId) { var item = CartItems.FirstOrDefault(i => i.ProductId.Equals(productId)); CartItems.Remove(item); }
public CartItem FindCartItem(Guid productId) { var cartItem = CartItems.FirstOrDefault(x => x.Product.ProductId == productId); return(cartItem); }
private CartItem GetCartItemByProductId(int id) { return(CartItems.FirstOrDefault(ci => ci.Product.ProductId == id)); }