Beispiel #1
0
        public void CartCheckout()
        {
            var FuncByType = new Dictionary <Type, Action <AbstractItem> > {
                { typeof(HeadItem), (ab) => hats.ItemUpdate((HeadItem)ab) },
                { typeof(BackItem), (ab) => bags.ItemUpdate((BackItem)ab) },
                { typeof(PrimaryWeapon), (ab) => primaryWeapons.ItemUpdate((PrimaryWeapon)ab) },
                { typeof(SecondaryWeapon), (ab) => secondaryWeapons.ItemUpdate((SecondaryWeapon)ab) }
            };

            List <AbstractItem> cart = new List <AbstractItem>();

            foreach (var item in shoppingCart)
            {
                AbstractItem it = item.Value;
                cart.Add(it);
                it.CurrentAmout--;
                if (FuncByType.ContainsKey(it.GetType()))
                {
                    FuncByType[it.GetType()].Invoke(it);
                }
                if (it.CurrentAmout == 0)
                {
                    OutOfStockEventHandler?.Invoke(this, it);
                }
            }
            CartItems.Add(new ShoppingCartItems(cart));
            shoppingCart.Clear();
        }
Beispiel #2
0
        public void RollupLineItemsFromPurchaseOrder(PurchaseOrder order)
        {
            if (CartItems.Count > 0)
            {
                Scout.Core.UserInteraction.Dialog.ShowMessage("Sales Order already contains line items.", UserMessageType.Error);
                return;
            }

            foreach (PurchaseLineItem item in order.LineItems)
            {
                if (item.OutgoingPart != null)
                {
                    SalesLineItem lineItem = GetLineByPart(item.OutgoingPart);
                    if (lineItem != null)
                    {
                        lineItem.Quantity += item.Quantity;
                    }
                    else
                    {
                        lineItem          = Scout.Core.Data.CreateEntity <SalesLineItem>(Session);
                        lineItem.Part     = item.OutgoingPart;
                        lineItem.Quantity = item.Quantity;
                        CartItems.Add(lineItem);
                    }
                }
            }

            CopyCustomerInfoFromPurchaseOrder(order);
        }
Beispiel #3
0
        }                                                 // Only next sequence discounts.

        public void AddItemToCart(IItem item)
        {
            if (item.Types == TypeOfProduct.Discount)
            {
                CartItems.Add(item);
                if (((IDiscount)item).DiscountingProductSequence == 0)
                {
                    AllDiscounts.Add(((IDiscount)item));
                }
                else
                {
                    Discounts.Enqueue((IDiscount)item);
                }
            }
            else
            {
                if (Discounts.Count > 0)
                {
                    var discountOnItem = Discounts.Dequeue();
                    DiscountingSystem.Instance.ApplyDiscount(discountOnItem, (IProduct)item);
                }
                else
                {
                    // going to apllied on all products.
                    foreach (var discount in AllDiscounts)
                    {
                        DiscountingSystem.Instance.ApplyDiscount(discount, (IProduct)item);
                    }
                }
            }
            CartItems.Add(item);
        }
        // Load cart from isolated storage.
        // Simple deserialization from disk.
        private void LoadCartFromIsolatedStorage()
        {
            var data = IsolatedStoreHelper.LoadData(cartPath);

            if (string.IsNullOrEmpty(data))
            {
                return;
            }

            string[] tokens = data.Split(';');
            ShippingId = int.Parse(tokens[0]);
            int count = int.Parse(tokens[1]);

            for (int i = 0; i < count; i++)
            {
                int index = 2 + (i * 4);
                CartItems.Add(new CartItem
                {
                    Id        = int.Parse(tokens[index + 0]),
                    Name      = tokens[index + 1],
                    Quantity  = int.Parse(tokens[index + 2]),
                    UnitPrice = double.Parse(tokens[index + 3])
                });
            }
        }
        async Task ExecuteLoadItemsCommand()    // Will load the items in this section
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                CartItems.Clear();
                ListCartItems = App.userCart.Items;
                var cartitems = ListCartItems;    // Add the list of menuItems from the userCart
                foreach (var menuitem in cartitems)
                {
                    CartItems.Add(menuitem);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #6
0
 public void Add(CartItem cartItem)
 {
     CartItems.Add(cartItem);
     TotalPrice = TotalPrice + double.Parse(cartItem.TotalPrice.Replace("٬", ""));
     Discount   = Discount + cartItem.Discount;
     Payment    = Payment + cartItem.Payment;
 }
        public bool AddToCart(CartItem newItem)
        {
            bool result = false;

            foreach (CartItem item in CartItems)
            {
                if (item.ItemId == newItem.ItemId)
                {
                    if (item.IsManaged)
                    {
                        doInTransaction(((o1, o2) => (o1 as CartItem).Quantity += (o2 as CartItem).Quantity), item, newItem);
                    }
                    else
                    {
                        item.Quantity += newItem.Quantity;
                    }
                    result = true;
                }
            }
            if (!result)
            {
                CartItems.Add(newItem);
                result = true;
            }
            SaveLocally();
            CalcTotalPrice();
            return(result);
        }
Beispiel #8
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
     }
 }
        CartItems GetCartItems()
        {
            CartItems results = new CartItems();

            try {
                var userId = Request.Cookies["cart"].Value;

                if (string.IsNullOrEmpty(userId))
                {
                    return(results);
                }

                var cartsCollection = Database.GetCollection <UserCart>("Carts");
                var cart            = cartsCollection.Find(x => x.UserId == userId).FirstOrDefault();

                if (cart == null)
                {
                    return(results);
                }

                foreach (var itemId in cart.Items)
                {
                    ObjectId obj = new MongoDB.Bson.ObjectId(itemId);
                    //   var results = _collection.Find(x => x.Name != "").ToList();
                    Thingy thing = _collection.Find(x => x.Id == obj).FirstOrDefault();
                    if (thing != null)
                    {
                        results.Add(thing);
                    }
                }
            }
            catch { }
            results.Items.Sort((x, y) => string.Compare(x.Thing.Name, y.Thing.Name));
            return(results);
        }
Beispiel #10
0
        public void AddBook(Book book)
        {
            CartItem NewBook = new CartItem(book);

            CartItems.Add(NewBook);
            Price += book.Price;
        }
        private async void OnItemAdded(CatalogItem catalogItem)
        {
            try
            {
                var cartItem = await _dataProvider.GetCartItemFromDataBase(catalogItem);

                CartItems.Add(cartItem);
                _chainOneTotal   += cartItem.ChainOneTotalPrice;
                _chainTwoTotal   += cartItem.ChainTwoTotalPrice;
                _chainThreeTotal += cartItem.ChainThreeTotalPrice;
                OnPropertyChanged(nameof(ChainOneTotal));
                OnPropertyChanged(nameof(ChainTwoTotal));
                OnPropertyChanged(nameof(ChainThreeTotal));
                if (CartItems.Count >= 6)
                {
                    UpdateLowAndHighPrices();
                }
                else
                {
                    ClearLowAndHighCollections();
                }
                InvalidateCommands();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void LoadCart()
        {
            var cartCookie = GetCookie(ShoppingCartCookieName);

            if (cartCookie == null || string.IsNullOrEmpty(cartCookie.Value))
            {
                return;
            }

            var products = cartCookie.Value.Split(',');

            foreach (var product in products)
            {
                var codeQuantity = product.Split('|');
                if (codeQuantity.Length != 2)
                {
                    continue;
                }
                uint quantity = 0;
                uint.TryParse(codeQuantity[1], out quantity);
                if (quantity < 1)
                {
                    continue;
                }
                CartItems.Add(codeQuantity[0], quantity);
            }
        }
        public CartItem InsertNewCartItem(int productId, int quantity, decimal displayedPrice)
        {
            var item = CartItem.Create(productId, quantity, displayedPrice, CartId);

            CartItems.Add(item);
            UpdateItemCount();
            return(item);
        }
Beispiel #14
0
        public void Add(CartItem cartItem)
        {
            CartItems.Add(cartItem);
            var tax = _taxCalculator.Calculate(cartItem);

            SetTotalCost(cartItem, _taxCalculator.Calculate(cartItem));
            SetTotalTax(cartItem, tax);
        }
 private void LoadCart()
 {
     foreach (CartItem ci in realm.All <CartItem>().AsRealmCollection())
     {
         CartItems.Add(ci);
     }
     CalcTotalPrice();
 }
Beispiel #16
0
        public void AddItem(Widget widget)
        {
            var cartItem = CartItems.Where(x => x.WidgetId == widget.WidgetId).FirstOrDefault();

            if (cartItem == null)
            {
                CartItems.Add(widget);
            }
        }
        public IActionResult AddToCart(int id)
        {
            List <int> CartItems = HttpContext.Session.Get <List <int> >("Cart");

            if (CartItems == null)
            {
                CartItems = new List <int>();
            }
            CartItems.Add(id);
            HttpContext.Session.Set("Cart", CartItems);

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #18
0
        public void AddCartItem(int?songID, int?albumID, float price)
        {
            var cartItem = new CartItem
            {
                SongID      = songID,
                AlbumID     = albumID,
                CreatedDate = DateTime.Now,
                Price       = price,
                Cart        = this
            };

            CartItems.Add(cartItem);
        }
Beispiel #19
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 #20
0
    public void AddItem(Guid itemId, string name, decimal price)
    {
        CartItem cartItem = CartItems.Find(x => x.ItemId == itemId);

        if (cartItem != null)
        {
            cartItem.Quantity += 1;
        }
        else
        {
            CartItems.Add(new CartItem(itemId, name, price, 1));
        }
    }
Beispiel #21
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);
        }
Beispiel #22
0
        public void AddProduct(Product product, int quantity)
        {
            CartItem cartItem = GetCartItemByProductId(product.ProductId);


            if (cartItem == null)
            {
                CartItems.Add(new CartItem {
                    Quantity = quantity, Product = product, CartItemId = Guid.NewGuid().ToString()
                });
            }
            else
            {
                cartItem.Quantity += quantity;
            }
        }
Beispiel #23
0
        private void LoadCart()
        {
            CartItems.Clear();
            GrandTotal = 0;
            var kids = UserProfileService.Instance.CurrentUserProfile.Kids;

            if (kids == null || kids.Count == 0)
            {
                kids = new List <string>()
                {
                    "My Child"
                };
            }
            foreach (var product in Products)
            {
                var productOrders = _orderHistoryService.Orders.Where(o => o.ProductType == product.Name && o.Status == (int)OrderStatus.Pending);
                if (productOrders.Any())
                {
                    foreach (var kid in kids)
                    {
                        var ordersByKid = productOrders.Where(o => o.Child == kid);
                        if (ordersByKid.Any())
                        {
                            decimal total = 0;
                            int     count = 0;
                            foreach (var o in ordersByKid)
                            {
                                count++;
                                total += product.Price;
                            }
                            var cartItem = new CartItem
                            {
                                Id          = Guid.NewGuid().ToString(),
                                Glyph       = product.Glyph,
                                Price       = product.Price.ToString("C"),
                                ProductType = product.Name,
                                Child       = kid,
                                Quantity    = count.ToString(),
                                Total       = total.ToString("C")
                            };
                            CartItems.Add(cartItem);
                            GrandTotal += total;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Add an product item to the shopping cart.
        /// </summary>
        /// <param name="newItem">The new cart item to be added.</param>
        public void AddItem(CartItem newItem)
        {
            // Check that item not already exists in shopping cart.
            foreach (var cartItem in CartItems)
            {
                if (cartItem.Id == newItem.Id)
                {
                    cartItem.Quantity += newItem.Quantity;
                    return;
                }
            }

            // A new item is added to shopping cart.
            CartItems.Add(newItem);

            CurrentItem = newItem;
        }
Beispiel #25
0
        /// <summary>
        /// 加入一项到购物车
        /// </summary>
        /// <param name="cartItem"></param>
        public void Add(ShoppingCartItem cartItem)
        {
            lock (_sync)
            {
                //Add options logic here
                ShoppingCartItem existsItem = CartItems.Find(p => p.SKU == cartItem.SKU);

                if (existsItem != null)
                {
                    existsItem.Quantity += cartItem.Quantity;
                }
                else
                {
                    CartItems.Add(cartItem);
                }
            }
        }
Beispiel #26
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 #27
0
        public int AddProduct(IProduct product, int amount = 1)
        {
            bool exist = CartProductIds.Contains(product.GetId());

            if (exist)
            {
                ICartItem item = CartItems.Find(cartItem => cartItem.GetProduct().Equals(product));
                if (item == null)
                {
                    throw new InvalidOperationException("Item exist in HashSet but not in CartItems");
                }
                return(item.IncreaseAmountOn(amount));
            }

            CartProductIds.Add(product.GetId());
            CartItems.Add(new CartItem(product, this, amount));
            return(amount);
        }
Beispiel #28
0
        public IActionResult AddToCart(int Id, int qty)
        {
            List <CartItem> CartItems;
            var             CartSession = HttpContext.Session.GetString("Cart");
            Cart            Cart;

            if (CartSession == null)
            {
                Cart      = new Cart();
                CartItems = new List <CartItem>();
            }
            else
            {
                Cart      = JsonConvert.DeserializeObject <Cart>(HttpContext.Session.GetString("Cart"));
                CartItems = Cart.ItemList;
            }

            SetBox sb = _setBoxService.GetById(Id);

            if (CartItems.Any(i => i.Product.Name == sb.Name))
            {
                CartItems.SingleOrDefault(i => i.Id == Id).Qty   += qty;
                CartItems.SingleOrDefault(i => i.Id == Id).Price += (qty * sb.Price);
            }
            else
            {
                CartItem item = new CartItem
                {
                    Id      = ++CartItemId,
                    Product = sb,
                    Qty     = qty,
                    Price   = qty * sb.Price
                };

                CartItems.Add(item);
            }
            Cart.ItemList   = CartItems;
            Cart.TotalPrice = Cart.ItemList.Sum(m => m.Price);
            Cart.TotalItems = Cart.ItemList.Sum(m => m.Qty);

            HttpContext.Session.SetString("Cart", JsonConvert.SerializeObject(Cart));
            return(RedirectToAction("Index"));
        }
Beispiel #29
0
        public void CopyItemsFromPurchaseOrder(PurchaseOrder order)
        {
            if (CartItems.Count > 0)
            {
                Scout.Core.UserInteraction.Dialog.ShowMessage("Sales Order already contains line items.", UserMessageType.Error);
                return;
            }

            foreach (PurchaseLineItem item in order.LineItems)
            {
                // Map the sales line item if the part does not exist already.
                if (GetItemId(item.Part.Id) == 0)
                {
                    CartItems.Add(new SalesItemMapper().MapFrom(item));
                }
            }

            CopyCustomerInfoFromPurchaseOrder(order);
        }
Beispiel #30
0
 /// <summary>
 /// 加入或更新购物车中的一项
 /// </summary>
 /// <param name="sku"></param>
 /// <param name="quantity"></param>
 public void AddorUpdate(string sku, int quantity)
 {
     lock (_sync)
     {
         ShoppingCartItem existsItem = CartItems.Find(p => p.SKU == sku);
         if (existsItem != null)
         {
             existsItem.Quantity += quantity;
         }
         else
         {
             CartItems.Add(new ShoppingCartItem
             {
                 SKU      = sku,
                 Quantity = quantity
             });
         }
     }
 }