public void AttachPromotionToItem(Item item, Promotion promotion) { if (item == null || promotion == null) { throw new ArgumentException(ERROR_MSG_CANNOT_ATTACH_NULL_ITEM_OR_PROMOTION); } if (DoesCartContainItem(item)) { LineItem lineItem = GetLineItemForItem(item); lineItem.Promotion = promotion; } }
private void button1_Click(object sender, EventArgs e) { txtTotal.Text = "0"; var obj = orders.FirstOrDefault(p => p.productId.ToString() == comboBox1.SelectedValue.ToString()); if (obj != null) { obj.qty = obj.qty + int.Parse(txtQty.Text); } else { orders.Add( new Order { id = decimal.Parse(DateTime.Now.ToString("ddMMyyyyhhmmss")), productId = int.Parse(comboBox1.SelectedValue.ToString()), qty = int.Parse(txtQty.Text.ToString()) } ); } double calAmt = 0; foreach (var item in orders) { Promotion pro = promotions.Find((Promotion p) => p.productId == item.productId); #region //IEnumerable<Promotion> pro = promotions.Where(p => p.productId == item.productId).OrderBy(p => p.productId); //foreach (var item2 in pro) //{ //} //var pro = promotions // .Where(p => p.productId == item.productId) // .OrderBy(p => p.productId) // .Select(p => p); #endregion Product product = products.Find((Product pr) => pr.id == item.productId); if (pro == null) { for (int i = 0; i < item.qty; i++) { calAmt += product.price; } } else { int actualDiscount = 0; int remainingQty = 0; remainingQty = checkPromotionItems(item.qty, pro.promotionItems, out actualDiscount); calAmt = calculateAmt(remainingQty, pro.promotionItems, pro.specialPrice, product.price, actualDiscount); remainingQty = 0; actualDiscount = 0; } txtTotal.Text = (double.Parse(txtTotal.Text) + calAmt).ToString(); } }