Beispiel #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
     }
 }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public void RemoveCartItemWithProduct(int productId)
        {
            var removedItem = CartItems.FirstOrDefault(x => x.ProductId == productId);

            if (removedItem != null)
            {
                CartItems.Remove(removedItem);
            }
        }
Beispiel #4
0
        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;
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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;
            }
        }
Beispiel #10
0
        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;
        }
Beispiel #11
0
        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();
        }
Beispiel #12
0
        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());
            }
        }
Beispiel #13
0
        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());
            }
        }
Beispiel #14
0
        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);
            }
        }
Beispiel #15
0
        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;
            }
        }
Beispiel #16
0
        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"));
        }
Beispiel #17
0
        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);
        }
Beispiel #18
0
        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();
        }
Beispiel #19
0
        public void RemoveProduct(int productId)
        {
            var item = CartItems.FirstOrDefault(i => i.ProductId.Equals(productId));

            CartItems.Remove(item);
        }
Beispiel #20
0
        public CartItem FindCartItem(Guid productId)
        {
            var cartItem = CartItems.FirstOrDefault(x => x.Product.ProductId == productId);

            return(cartItem);
        }
Beispiel #21
0
 private CartItem GetCartItemByProductId(int id)
 {
     return(CartItems.FirstOrDefault(ci => ci.Product.ProductId == id));
 }