private void btn_order_click(object sender, RoutedEventArgs e) { if (txtb_productQuantity.Text == "" || txtb_productQuantity.Text == "0") { MessageBox.Show("invalid entry"); return; } else if (p == null) { MessageBox.Show("Please Select a Product"); return; } OrderDetails od = new OrderDetails() { OrderId = order.Id, ProductId = p.Id, Quantity = int.Parse(txtb_productQuantity.Text), UnitPrice = p.Price }; _ods.Add(od); txtb_productQuantity.Text = "0"; if (lst_Order.Items != null) { itemCount += od.Quantity; totalPrice += od.UnitPrice * od.Quantity; lst_Order.Items.Add(new { ProductName = _ps.GetProductName(od.ProductId), Quantity = od.Quantity, Price = od.UnitPrice, SubTotal = od.Quantity * od.UnitPrice }); } //else //{ // var or = _os.GetOrder(1); // if (or != null) // { // var list = _ods.GetOrderDetails(or.Id); // foreach (var orderDetail in list) // { // itemCount += orderDetail.Quantity; // totalPrice += orderDetail.UnitPrice; // lst_Order.Items.Add(new { ProductName = _ps.GetProductName(orderDetail.ProductId), Quantity = orderDetail.Quantity, Price = orderDetail.UnitPrice, SubTotal = orderDetail.Quantity * orderDetail.UnitPrice }); // } // } //} lbl_items.Content = itemCount; lbl_Total.Content = totalPrice; }