// Display receipt and ask for payment method private async void btnCheckOut_Click(object sender, RoutedEventArgs e) { string summary = ""; SubTotal = 0; btnRefresh_Click(this, new RoutedEventArgs()); // Abort action when cart is empty if (Cart.Items.Count == 0) { var dlgEmpty = new ContentDialog { Title = "Unable to checkout", Content = "There are no item placed in cart", PrimaryButtonText = "OK" }; MainPage.ReplaceDialog(dlgEmpty, sender); try { await dlgEmpty.ShowAsync(); return; } catch (Exception) { /*The dialog didn't open, probably because another dialog is already open.*/ } } // generate receipt string receipt = "\n\t Papa Dario's Pizza"; receipt += "\n\tOrdered at: " + DateTime.Now.ToString(); receipt += "\n----------------------------------------------\n\n"; foreach (Item item in Cart.Items) { receipt += item.PricedString() + "\n\n"; SubTotal += item.SubTotal; summary += item.Summary + "\n"; } if (globalProperties.IsLoggedIn) { SubTotal = (float)(SubTotal * 0.9); } Tax = (float)Math.Round((0.13 * (double)SubTotal), 2); receipt += "----------------------------------------------\n"; receipt += String.Format("{0, 38} {1, 7}\n", "Subtotal:", "$" + Math.Round(SubTotal, 2)); receipt += String.Format("{0, 38} {1, 7}\n", "Tax:", "$" + Math.Round(Tax, 2)); receipt += String.Format("{0, 38} {1, 7}\n", "Total:", "$" + Math.Round((SubTotal + Tax), 2)); receipt += "\n\n Thank you for purchasing from Papa Dario's!"; var dlg = new ReceiptDialog(receipt); MainPage.ReplaceDialog(dlg, sender); try { var result = await dlg.ShowAsync(); if (result == ContentDialogResult.Primary) { int orderId = globalProperties.PlaceOrder(summary, Math.Round(SubTotal, 2), Math.Round(Tax, 2), Math.Round((SubTotal + Tax), 2)); foreach (Item item in Cart.Items) { globalProperties.PlaceOrderedItem(orderId, item.Summary); } Cart.Items.Clear(); var dlgSuccess = new ContentDialog { Title = "Order Placed", Content = "Thank you for ordering from Papa Dario's!", PrimaryButtonText = "Close" }; MainPage.ReplaceDialog(dlgSuccess, sender); await dlgSuccess.ShowAsync(); ContentFrame.Navigate(typeof(CartPage)); } return; } catch (Exception) { /*The dialog didn't open, probably because another dialog is already open.*/ } }