Ejemplo n.º 1
0
        /// <summary>
        /// Remove from stock 'amountToBuy' products
        /// </summary>
        /// <param name="numberToRemove"></param>
        /// <returns>new amount id succeed ,otherwise -1</returns>
        private int removeFromStock(Product p, int amountToBuy)
        {
            if (!amountIsLegal(p.amount - amountToBuy))
            {
                return(-1);
            }

            p.amount -= amountToBuy;
            WorkShop.Update(this);
            return(p.amount);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// succseed - callback that return the products to the stock. if fail - returns null
        /// </summary>
        /// <param name="user"></param>
        /// <param name="p"></param>
        /// <param name="amountToBuy"></param>
        /// <returns> succseed - callback that return the products to the stock., fail - returns null</returns>
        public callback buyProduct(Product p, int amountToBuy)
        {
            callback callback = delegate()
            {
                if (GetStockAsDictionary().ContainsKey(p.getId()))
                {
                    GetStockAsDictionary()[p.getId()].amount += amountToBuy;
                }
                WorkShop.Update(this);
            };

            if (!GetStockAsDictionary().ContainsKey(p.getId()) || removeFromStock(GetStockAsDictionary()[p.getId()], amountToBuy) == -1)
            {
                return(null);
            }
            return(callback);
        }