Exemple #1
0
        public void OnBtnAddClick(object obj)
        {
            if (!(obj is FoodProduct menuItem))
            {
                return;
            }
            var item = BasketItems.Find(x => x.MiGuid == menuItem.MiId);

            if (item != null)
            {
                item.MiQuantity++;
                ItemsBasket_CollectionChanged();
                return;
            }
            BasketItems.Add(new Models.BasketItem {
                MiGuid = menuItem.MiId, MiName = menuItem.MiName, MiImage = menuItem.MiImage, MiPrice = menuItem.MiPrice, MiQuantity = 1
            });
            ItemsBasket_CollectionChanged();
        }
        public override decimal CalculateBasketTotal()
        {
            decimal total = base.CalculateBasketTotal();

            decimal discountPrice = 0.00M;
            int     discounts     = 0;

            if (base.BasketItems.Exists(x => x.Name == _sourceItem && x.Quantity >= 2) && base.BasketItems.Exists(x => x.Name == _targetItem))
            {
                int sourceCount = base.BasketItems.Find(x => x.Name == _sourceItem).Quantity;
                int targetCount = base.BasketItems.Find(x => x.Name == _targetItem).Quantity;
                for (int i = 1; i <= sourceCount && discounts < targetCount; i++)
                {
                    if (i % 2 == 0)
                    {
                        discounts++;
                    }
                    discountPrice = (BasketItems.Find(x => x.Name == _targetItem).Cost * 50 / 100) * discounts;
                }
            }

            return(total - discountPrice);
        }
Exemple #3
0
 public BasketItem Find(string name)
 {
     return(BasketItems.Find(item => item.ProductName == name));
 }