private async void AddProduct(Product product) { this.decimalTextBox.Text = "1"; this.quantityDialog.Content = this.decimalTextBox; this.quantityDialog.Title = "Enter quantity"; ContentDialogResult result = await this.ShowQuantityDialog(); if (result == ContentDialogResult.Primary) { TextBox input = (TextBox)quantityDialog.Content; decimal.TryParse(input.Text, out decimal quantity); if (quantity == 0) { quantity = 1; } if (quantity <= product.Quantity) { if (OrderItems.Any(p => p.OrderItem.ProductId == product.ProductId)) { OrderItemListView existingItem = OrderItems.FirstOrDefault(p => p.OrderItem.ProductId == product.ProductId); int index = OrderItems.IndexOf(existingItem); existingItem.OrderItem.Quantity += quantity; OrderItemListView orderItemListView = this.GetDuplicatedItem(existingItem); OrderItems.RemoveAt(index); OrderItems.Insert(index, orderItemListView); } else { OrderItemListView orderItem = new OrderItemListView { OrderItem = new OrderItem { Product = product, ProductId = product.ProductId, Quantity = quantity, LineDiscount = 0, SubTotal = this.GetSubTotal(product.SellingPrice, quantity, 0) } }; orderItem.ItemDeleteClicked += this.HandleItemDeleted; OrderItems.Add(orderItem); } RaisePropertyChanged("OrderItems"); RaisePropertyChanged("IsProceedEnabled"); } else { this.messageDialog.Content = "Insufficient quantity !"; await this.messageDialog.ShowAsync(); } this.SearchText = product.Name; } this.SearchText = string.Empty; }