private void btnAddProductToList_Click(object sender, EventArgs e) { SetTotalPrice(); Product product = productController.GetProductById (Convert.ToInt32(cmbProductList.SelectedValue)); string addedProductDetail; foreach (var item in productsInCart) { if (item.ProductID == product.ProductID) { item.Quantity += Convert.ToInt32(numericQuantity.Value); MessageBox.Show($"There is already a product named {product.ProductName} in the shopping cart. On checkout, first discount rate will be applied on the extra products."); addedProductDetail = $"{product.ProductName}, Quantity:{numericQuantity.Value}, Total Price:{priceWithoutDiscount}"; lstAddedProducts.Items.Add(addedProductDetail); return; } } addedProductDetail = $"{product.ProductName}, Quantity:{numericQuantity.Value}, Total Price:{finalPrice}"; lstAddedProducts.Items.Add(addedProductDetail); ShoppingCartAddedProduct addedProduct = new ShoppingCartAddedProduct { ProductID = product.ProductID, Quantity = Convert.ToInt32(numericQuantity.Value), UnitPrice = (decimal)product.UnitPrice, Discount = Convert.ToDecimal(cmbDiscountList.SelectedValue) }; productsInCart.Add(addedProduct); }
void Apply(ShoppingCartAddedProduct e) { var temp = _items.SingleOrDefault(i => i.ProductId == e.ProductId); if (temp == null) { _items.Add(new ShoppingCartItem() { ProductId = e.ProductId, UnitPrice = e.UnitPrice, Quantity = e.Quantity, TotalPrice = e.TotalPrice }); } else { temp.Quantity = e.Quantity; temp.TotalPrice = e.TotalPrice; temp.UnitPrice = e.UnitPrice; } }
public void Handle(ShoppingCartAddedProduct e) { PreCalculateShoppingCart(e.Id, e.ProductId, e.Quantity); }