private async Task makePaymentOnline(Library.Models.Order value) { Response <string> orderId = await APIHelper.Instance.Post <Response <string> > (ApiRoutes.Order.createOrder, value); List <DisplayCart> listCart = this.cartPanel.Children.OfType <DisplayCart>().ToList <DisplayCart>(); foreach (var item in listCart) { OrderDetail orderDetail = new OrderDetail(); orderDetail.OrderId = orderId.Result; orderDetail.ProductId = item.cart.ProductId; orderDetail.Quantity = item.cart.Quantity; Response <object> orderDetailResponse = await APIHelper.Instance.Post <Response <object> > (ApiRoutes.Order.createOrderDetail, orderDetail); Response <object> paymentResponse = await APIHelper.Instance.Post <Response <object> > (ApiRoutes.Account.makePayment, orderDetail); } foreach (var item in listCart) { item.clearCart(); } }
private async void CheckoutClick(object sender, RoutedEventArgs e) { if (!totalMoneyText.Text.Contains("Total")) { return; } AddressWindow getAddress = new AddressWindow(); getAddress.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner; Nullable <bool> dialogResult = getAddress.ShowDialog(); MessageBoxResult onlinePayment = Xceed.Wpf.Toolkit.MessageBox.Show("Would you like to pay online ?", "onlinePayment", MessageBoxButton.YesNo); if (dialogResult == true) { Library.Models.Order newOrder = new Library.Models.Order(); newOrder.UserId = AuthenticatedUser.user.UserId; newOrder.Address = getAddress.deliveryAddress; newOrder.Date = string.Format("{0:yyyy/MM/dd HH:mm:ss}", DateTime.Now.ToString()); newOrder.isArrived = 0; newOrder.Total = totalMoney; if (onlinePayment == MessageBoxResult.Yes) { string getBalanceUrl = ApiRoutes.Account.getCurrentBalance.Replace("{id}", AuthenticatedUser.user.UserId); Response <double> currentBalance = await APIHelper.Instance.Get <Response <double> >(getBalanceUrl); if (currentBalance.Result < totalMoney) { Xceed.Wpf.Toolkit.MessageBox.Show("You dont have enough money", "onlinePayment", MessageBoxButton.OKCancel); return; } else { newOrder.isPaid = 1; await makePaymentOnline(newOrder); } } else { newOrder.isPaid = 0; await createOrderOnly(newOrder); } } else { return; } }