/// <summary> /// A method for entering the quantity of an item in a product /// </summary> private void SaveExecute() { try { if (addOrderItem.txtQuantity.Text.Length < 1) { Xceed.Wpf.Toolkit.MessageBox.Show("Enter a number.", "Wrong input", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (addOrderItem.txtQuantity.Text.ToString() == "0" || addOrderItem.txtQuantity.Text.ToString() == "00") { Xceed.Wpf.Toolkit.MessageBox.Show("Quantity must be greater than zero.", "Wrong input", MessageBoxButton.OK, MessageBoxImage.Warning); return; } Service s = new Service(); string productName = addOrderItem.txtName.Text; tblProduct menu = s.GetProductID(Convert.ToString(productName)); using (PizzaRestoranEntities context = new PizzaRestoranEntities()) { tblOrderItem tblOrderItem = new tblOrderItem(); OrderList = s.GetAllOrder(); tblOrderItem.ProductName = menu.ProductID; tblOrderItem.ProductPrice = Convert.ToInt32(addOrderItem.txtPrice.Text); tblOrderItem.ProductQuantity = Convert.ToInt32(addOrderItem.txtQuantity.Text); tblOrderItem.OrderName = OrderList.LastOrDefault().OrderID; tblOrderItem.OrderSum = Convert.ToInt32(addOrderItem.txtPrice.Text) * Convert.ToInt32(addOrderItem.txtQuantity.Text); context.tblOrderItems.Add(tblOrderItem); context.SaveChanges(); } IsUpdateItem = true; addOrderItem.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }