Ejemplo n.º 1
0
        public bool setProductAmount(Store store, Product product, int amount)
        {
            Predicate <ShoppingCartAndStore> cartPredicat = s => ((ShoppingCartAndStore)s).store.Equals(store);
            ShoppingCartAndStore             cartAndStore = cartsList.Find(cartPredicat);

            //remove product from list
            if (amount == 0)
            {
                //check if the storecart is empty now
                if (containStore(cartPredicat))
                {
                    ShoppingCart cart = cartAndStore.cart;
                    //set product amount to zero
                    cart.setProductAmount(product, amount);
                    int storeAmount = cart.getTotalAmount();
                    if (storeAmount == 0)
                    {
                        cartsList.Remove(cartAndStore);
                    }
                    WorkshopProject.Log.Logger.Log("event", logLevel.INFO, $"set product {product.getId()} amount {amount} to basket {id}");
                }
                return(true);
            }
            else if (amount > 0)
            {
                if (containStore(cartPredicat))
                {
                    ShoppingCart cart = cartAndStore.cart;
                    WorkshopProject.Log.Logger.Log("event", logLevel.INFO, $"set product {product.getId()} amount {amount} to basket {id}");
                    return(cart.setProductAmount(product, amount));
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
 public override void Copy(IEntity other)
 {
     base.Copy(other);
     if (other is ShoppingCartAndStore)
     {
         ShoppingCartAndStore _other = ((ShoppingCartAndStore)other);
         store = _other.store;
         cart  = _other.cart;
     }
 }
Ejemplo n.º 3
0
        public bool addProduct(Store store, Product product, int amount)
        {
            Predicate <ShoppingCartAndStore> cartPredicat = s => ((ShoppingCartAndStore)s).store.Equals(store);
            ShoppingCartAndStore             cartAndStore = cartsList.Find(cartPredicat);
            ShoppingCart cart;

            if (!containStore(cartPredicat))
            {
                cart = new ShoppingCart();
                cartsList.Add(new ShoppingCartAndStore(store, cart));
                WorkshopProject.Log.Logger.Log("event", logLevel.INFO, $"add product {product.getId()} amount {amount} to basket {id}");
            }
            else
            {
                cart = cartsList.Find(cartPredicat).cart;
                WorkshopProject.Log.Logger.Log("event", logLevel.INFO, $"set product {product.getId()} amount {amount} to basket {id}");
            }
            return(cart.addProducts(product, amount));
        }