Beispiel #1
0
        /// <summary>
        /// Calculates the basket item.
        /// </summary>
        /// <param name="itemname">The itemname.</param>
        /// <param name="quantity">The quantity.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public bool CalculateBasketItem(string itemname, int quantity)
        {
            bool rtn = false;

            Good good = goodsManager.SearchAGood(itemname);

            if (good != null)
            {
                var qry = BasketDetails.BasketList.SingleOrDefault(b => b.Item == itemname);
                if (qry != null)
                {
                    qry.Quantity  += quantity;
                    qry.FinalPrice = CalculatePrice(good, qry.Quantity);

                    if (qry.FinalPrice > 0)
                    {
                        AddHistory(HistoryUpdate, itemname, qry.Price, qry.FinalPrice, (qry.Price * qry.Quantity) != qry.FinalPrice);
                        rtn = true;
                    }
                }
                else
                {
                    BasketItem bi = new BasketItem()
                    {
                        Item = good.Item, Price = good.Price, Quantity = quantity
                    };
                    bi.FinalPrice = CalculatePrice(good, bi.Quantity);
                    BasketDetails.BasketList.Add(bi);

                    if (bi.FinalPrice > 0)
                    {
                        AddHistory(HistoryAddNew, itemname, bi.Price, bi.FinalPrice, (bi.Price * bi.Quantity) != bi.FinalPrice);
                        rtn = true;
                    }
                }
            }

            return(rtn);
        }